Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Asp

754 views

Published on

A sample ASP.net with C# interview questions & answers for beginners.Hope it will help you guys.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Asp

  1. 1. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 1 1. What is ASP? Active Server Pages (ASP), also known as Classic ASP, is a Microsoft's server-side technology, which helps in creating dynamic and user-friendly Web pages. It uses different scripting languages to create dynamic Web pages, which can be run on any type of browser. The Web pages are built by using either VBScript or JavaScript and these Web pages have access to the same services as Windows application, including ADO (ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer Protocol) for e-mail, and the entire COM (Component Object Model) structure used in the Windows environment. ASP is implemented through a dynamic-link library (asp.dll) that is called by the IIS server when a Web page is requested from the server. 2. What is ASP.NET? ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application. 3. What is the basic difference between ASP and ASP.NET? The basic difference between ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled. This implies that since ASP uses VBScript; therefore, when an ASP page is
  2. 2. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 2 executed, it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL). 4. In which event are the controls fully loaded? Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event 5. How can we identify that the Page is Post Back? Page object has an "IsPostBack" property, which can be checked to know that is the page posted back. 6. What is the lifespan for items stored in ViewState? The items stored in ViewState live until the lifetime of the current page expires including the postbacks to the same page. 7. How information about the user's locale can be accessed? The information regarding a user's locale can be accessed by using the System.Web.UI.Page.Culture property. 8. What is the difference between SQL notification and SQL invalidation? The SQL cache notification generates notifications when the data of a database changes, on which your cache item depends. The SQL cache invalidation makes a cached item invalid when the data stored in a SQL server database changes. 9. Which is the parent class of the Web server control? The System.Web.UI.Control class is the parent class for all Web server controls.
  3. 3. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 3 10. Can you set which type of comparison you want to perform by the CompareValidator control? Yes, by setting the Operator property of the CompareValidator control. 11. What is the behavior of a Web browser when it receives an invalid element? The behavior of a Web browser when it receives an invalid element depends on the browser that you use to browse your application. Most of the browsers ignore the invalid element; whereas, some of them display the invalid elements on the page. 12. What are the advantages of the code-behind feature? The code-behind feature of ASP.NET offers a number of advantages: Makes code easy to understand and debug by separating application logic from HTML tags Provides the isolation of effort between graphic designers and software engineers Removes the problems of browser incompatibility by providing code files to exist on the Web server and supporting Web pages to be compiled on demand. 13. How do you sign out from forms authentication? The FormsAuthentication.Signout() method is used to sign out from the forms authentication. 14. What is AutoPostBack? If you want a control to postback automatically when an event is raised, you need to set the AutoPostBack property of the control to True. 15. What is the function of the ViewState property?
  4. 4. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 4 The ASP.NET 4.0 introduced a new property called ViewStateMode for the Control class. Now you can enable the view state to an individual control even if the view state for an ASP.NET page is disabled. 16. Why do you use the App_Code folder in ASP.NET? The App_Code folder is automatically present in the project. It stores the files, such as classes, typed data set, text files, and reports. If this folder is not available in the application, you can add this folder. One of the important features of the App_Code folder is that only one dll is created for the complete folder, irrespective of how many files it contains. 17. Define a multilingual Web site. A multilingual Web site serves content in a number of languages. It contains multiple copies for its content and other resources, such as date and time, in different languages. 18. What is an ASP.NET Web Form? ASP.NET Web forms are designed to use controls and features that are almost as powerful as the ones used with Windows forms, and so they are called as Web forms. The Web form uses a server-side object model that allows you to create functional controls, which are executed on the server and are rendered as HTML on the client. The attribute, runat="server", associated with a server control indicates that the Web form must be processed on the server. 19. What is the difference between a default skin and a named skin? The default skin is applied to all the Web server controls in a Web form, which are of similar type, and it does not provide a Skin ID attribute. The named skin provides a Skin ID attribute and users have to set the Skin ID property to apply it.
  5. 5. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 5 20. What is IIS? Why is it used? Internet Information Services (IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web applications. It makes your computer to work as a Web server and provides the functionality to develop and deploy Web applications on the server. IIS handles the request and response cycle on the Web server. It also offers the services of SMTP and FrontPage server extensions. The SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handler. 21. What is Query String? What are its advantages and limitations? The Query String helps in sending the page information to the server. The Query String has the following advantages: Every browser works with Query Strings. It does not require server resources and so does not exert any kind of burden on the server. The following are the limitations of Query String: Information must be within the limit because URL does not support many characters. Information is clearly visible to the user, which leads to security threats. 22. What is actually returned from server to the browser when a browser requests an .aspx file and the file is displayed? When a browser requests an .aspx file then the server returns a response, which is rendered into a HTML string. 23. How can you display all validation messages in one control? The ValidationSummary control displays all validation messages in one control.
  6. 6. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 6 24. Which two new properties are added in ASP.NET 4.0 Page class? The two new properties added in the Page class are MetaKeyword and MetaDescription. 25. What is tracing? Where is it used? Tracing displays the details about how the code was executed. It refers to collecting information about the application while it is running. Tracing information can help you to troubleshoot an application. It enables you to record information in various log files about the errors that might occur at run time. You can analyze these log files to find the cause of the errors. In .NET, we have objects called Trace Listeners. A listener is an object that gets the trace output and stores it to different places, such as a window, a file on your locale drive, or a SQL Server. The System.Diagnostics namespace contains the predefined interfaces, classes, and structures that are used for tracing. It supplies two classes, Trace and Debug, which allow you to write errors and logs related to the application execution. Trace listeners are objects that collect the output of tracing processes. 26. What is the difference between authentication and authorization? Authentication verifies the identity of a user and authorization is a process where you can check whether or not the identity has access rights to the system. In other words, you can say that authentication is a procedure of getting some credentials from the users and verify the user's identity against those credentials. Authorization is a procedure of granting access of particular resources to an authenticated user. You should note that authentication always takes place before authorization. 27. How can you register a custom server control to a Web page?
  7. 7. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 7 You can register a custom server control to a Web page using the @Register directive. 28. Which ASP.NET objects encapsulate the state of the client and the browser? The Session object encapsulates the state of the client and browser. 29. Differentiate globalization and localization. The globalization is a technique to identify the specific part of a Web application that is different for different languages and make separate that portion from the core of the Web application. The localization is a procedure of configuring a Web application to be supported for a specific language or locale. 30. What is ViewState? The ViewState is a feature used by ASP.NET Web page to store the value of a page and its controls just before posting the page. Once the page is posted, the first task by the page processing is to restore the ViewState to get the values of the controls. 31. Which method is used to force all the validation controls to run? The Page.Validate() method is used to force all the validation controls to run and to perform validation. 32. Which method has been introduced in ASP.NET 4.0 to redirect a page permanently? The RedirectPermanent() method added in ASP.NET 4.0 to redirect a page permanently. The following code snippet is an example of the RedirectPermanent() method: RedirectPermanent("/path/Aboutus.aspx");
  8. 8. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 8 33. How can you send an email message from an ASP.NET Web page? You can use the System.Net.Mail.MailMessage and the System.Net.Mail.SmtpMail classes to send an email in your Web pages. In order to send an email through your mail server, you need to create an object of the SmtpClient class and set the server name, port, and credentials. 34. What is the difference between the Response.Write() and Response.Output.Write() methods? The Response.Write() method allows you to write the normal output; whereas, the Response.Output.Write() method allows you to write the formatted output. 35. What does the Orientation property do in a Menu control? Orientation property of the Menu control sets the horizontal or vertical display of a menu on a Web page. By default, the orientation is vertical. 36. Differentiate between client-side and server-side validations in Web pages. Client-side validations take place at the client end with the help of JavaScript and VBScript before the Web page is sent to the server. On the other hand, server-side validations take place at the server end. 37. How does a content page differ from a master page? A content page does not have complete HTML source code; whereas a master page has complete HTML source code inside its source file.
  9. 9. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 9 38. Suppose you want an ASP.NET function (client side) executed on the MouseOver event of a button. Where do you add an event handler? The event handler is added to the Add() method of the Attributes property. 39. What is the default timeout for a Cookie? The default time duration for a Cookie is 30 minutes. 40. What are HTTP handlers in ASP.NET? HTTP handlers, as the name suggests, are used to handle user requests for Web application resources. They are the backbone of the request-response model of Web applications. There is a specific event handler to handle the request for each user request type and send back the corresponding response object. Each user requests to the IIS Web server flows through the HTTP pipeline, which refers to a series of components (HTTP modules and HTTP handlers) to process the request. HTTP modules act as filters to process the request as it passes through the HTTP pipeline. The request, after passing through the HTTP modules, is assigned to an HTTP handler that determines the response of the server to the user request. The response then passes through the HTTP modules once again and is then sent back to the user. You can define HTTP handlers in the <httpHandlers> element of a configuration file. The <add> element tag is used to add new handlers and the <remove> element tag is used to remove existing handlers. To create an HTTP handler, you need to define a class that implements the IHttpHandler interface. 41. What are the events that happen when a client requests an ASP.NET page from IIS server?
  10. 10. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 10 The following events happen when a client requests an ASP.NET page from the IIS server: User requests for an application resource. The integrated request-processing pipeline receives the first user request. Response objects are created for each user request. An object of the HttpApplication class is created and allocated to the Request object. The HttpApplication class processes the user request. 42. Explain file-based dependency and key-based dependency. In file-based dependency, you have to depend on a file that is saved in a disk. In key-based dependency, you have to depend on another cached item. 43. How can you implement the postback property of an ASP.NET control? You need to set the AutoPostBack property to True to implement the PostBack property of controls. 44. Explain how Cookies work. Give an example of Cookie abuse. The server tells the browser to put some files in a cookie, and the client then sends all the cookies for the domain in each request. An example of cookie abuse is large cookies affecting the network traffic. 45. Explain login controls. Login controls are built-in controls in ASP.Net for providing a login solution to ASP.NET application. The login controls use the membership system to authenticate a user credentials for a Web site. There are many controls in login controls. ChangePassword control - Allows users to change their password. CreateUserWizard control - Provides an interface to the user to register for that Web site.
  11. 11. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 11 Login control - Provides an interface for user authentication. It consists of a set of controls, such as TextBox, Label, Button, CheckBox, HyperLink. LoginView control - Displays appropriate information to different users according to the user's status. LoginStatus control - Shows a login link to users, who are not authenticated and logout link, who are authenticated LoginName control - Displays a user name, if the user logs in. PasswordRecovery control - Allows users to get back the password through an e-mail, if they forget. 46. What is the use of PlaceHolder control? Can we see it at runtime? The PlaceHolder control acts as a container for those controls that are dynamically generated at runtime. We cannot see it at runtime because it does not produce any visible output. It used only as a container. 47. What setting must be added in the configuration file to deny a particular user from accessing the secured resources? To deny a particular user form accessing the secured resources, the web.config file must contain the following code: <authorization > <deny users="username" /> </authorization> 48. What are the event handlers that can be included in the Global.asax file? The Global.asax file contains some of the following important event handlers: Application_Error Application_Start Application_End Session_Start Session_End
  12. 12. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 12 49. What is the difference between page-level caching and fragment caching? In the page-level caching, an entire Web page is cached; whereas, in the fragment caching, a part of the Web page, such as a user control added to the Web page, is cached. 50. Make a list of all templates of the Repeater control. The Repeater control contains the following templates: ItemTemplate AlternatingltemTemplate SeparatorTemplate HeaderTemplate FooterTemplate 51. Describe the complete lifecycle of a Web page. When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle: Page request - During this stage, ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response Start - During this stage sets the Request and Response page properties and the page check the page request is either a postback or a new request Page Initialization - During this stage, the page initialize and the control's Unique Id property are set Load - During this stage, if the request is postback, the control properties are loaded without loading the view state and control state otherwise loads the view state Validation - During this stage, the controls are validated Postback event handling - During this stage, if the request is a postback, handles the event Rendering - During this stage, the page invokes the Render method to each control for return the output Unload - During this stage, when the page is completely rendered and sent to the client, the page is unloaded.
  13. 13. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 13 52. How can you assign page specific attributes in an ASP.NET application? The @Page directive is responsible for this. 53. Which method is used to post a Web page to another Web page? The Respose.Redirect method is used to post a page to another page, as shown in the following code snippet: Response.Redirect("DestinationPageName.aspx"); 54. What is a Cookie? Where is it used in ASP.NET? Cookie is a lightweight executable program, which the server posts to client machines. Cookies store the identity of a user at the first visit of the Web site and validate them later on the next visits for their authenticity. The values of a cookie can be transferred between the user's request and the server's response. 55. What are Custom User Controls in ASP.NET? The custom user controls are the controls that are defined by developers. These controls are a mixture of custom behavior and predefined behavior. These controls work similar to other Web server controls. 56. What does the .WebPart file do? The .WebPart file explains the settings of a Web Parts control that can be included to a specified zone on a Web page. 57. How can you enable impersonation in the web.config file? To enable impersonation in the web.confing file, you need to include the <identity> element in the web.config file and set the impersonate attribute to true as shown in the following code snippet: <identity impersonate = "true" />
  14. 14. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 14 58. How can you identify that the page is PostBack? The Page object uses the IsPostBack property to check whether the page is posted back or not. If the page is postback, this property is set to true. 59. In which database is the information, such as membership, role management, profile, and Web parts personalization, stored? The aspnetdb database stores all information. 60. What is State Management? How many ways are there to maintain a state in .NET? State management is used to store information requests. The state management is used to trace the information or data that affect the state of the applications. There are two ways to maintain a state in .NET, Client-Based state management and Server-Based state management. The following techniques can be used to implement the Client-Based state management: View State Hidden Fields Cookies Query Strings Control State The following techniques can be used to implement Server-Based state management: Application State Session State Profile Properties 61. What do you understand by aggregate dependency?
  15. 15. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 15 Aggregate dependency allows multiple dependencies to be aggregated for content that depends on more than one resource. In such type of dependency, you need to depend on the sum of all the defined dependencies to remove a data item from the cache. 62. How can you ensure that no one has tampered with ViewState in a Web page? To ensure that no one has tampered with ViewState in a Web page, set the EnableViewStateMac property to True. 63. What is the difference between adding items into cache through the Add() method and through the Insert() method? Both methods work in a similar way except that the Cache.Add() function returns an object that represents the item you added in the cache. The Cache.Insert() function can replace an existing item in the cache, which is not possible using the Cache.Add() method. 64. Explain the cookie less session and its working. ASP.NET manages the session state in the same process that processes the request and does not create a cookie. It is known as a cookie less session. If cookies are not available, a session is tracked by adding a session identifier to the URL. The cookie less session is enabled using the following code snippet: <sessionState cookieless="true" /> 65. What is a round trip? The trip of a Web page from the client to the server and then back to the client is known as a round trip. 66. What are the major built-in objects in ASP.NET? The major built-in objects in ASP.NET are as follows:
  16. 16. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 16 Application Request Response Server Session Context Trace 67. Where should the data validations be performed-at the client side or at the server side and why? Data validations should be done primarily at the client side and the server-side validation should be avoided because it makes server task overloaded. If the client-side validation is not available, you can use server-side validation. When a user sends a request to the server, the validation controls are invoked to check the user input one by one. 68. Why do we need nested master pages in a Web site? When we have several hierarchical levels in a Web site, then we use nested master pages in the Web site. 69. How can you dynamically add user controls to a page? User controls can be dynamically loaded by adding a Web User Control page in the application and adding the control on this page. 70. What is the appSettings Section in the web.config file? The web.config file sets the configuration for a Web project. The appSettings block in configuration file sets the user-defined values for the whole application. For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:
  17. 17. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 17 <configuration> <appSettings> <add key="ConnectionString" value="server=indiabixserver; pwd=dbpassword; database=indiabix" /> </appSettings> ... 71. What type of code, client-side or server-side, is found in a code-behind file of a Web page? A code-behind file contains the server-side code, which means that the code contained in a code-behind file is executed at the server. 72. To which class a Web form belongs to in the .NET Framework class hierarchy? A Web form belongs to the System.Web.UI.Page class. 73. What does the "EnableViewState" property do? Why do we want it On or Off? The EnableViewState property enables the ViewState property on the page. It is set to On to allow the page to save the users input between postback requests of a Web page; that is, between the Request and corresponding Response objects. When this property is set to Off, the page does not store the users input during postback. 74. Which event determines that all the controls are completely loaded into memory? The Page_Load event determines that all the controls on the page are fully loaded. You can also access the controls in the Page_Init event; however, the ViewState property does not load completely during this event. 75. What is the function of the CustomValidator control?
  18. 18. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 18 It provides the customize validation code to perform both client-side and server-side validation. 76. What is Role-based security? In the Role-based security, you can assign a role to every user and grant the privilege according to that role. A role is a group of principal that restricts a user's privileges. Therefore, all the organization and applications use role-based security model to determine whether a user has enough privileges to perform a requested task. 77. Which data type does the RangeValidator control support? The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date. 78. What are the HTML server controls in ASP.NET? HTML server controls are similar to the standard HTML elements, which are normally used in HTML pages. They expose properties and events that can be used programmatically. To make these controls programmatically accessible, you need to specify that the HTML controls act as a server control by adding the runat="server" attribute. 79. Why a SiteMapPath control is referred to as breadcrumb or eyebrow navigation control? The SiteMapPath control displays a hierarchical path to the root Web page of the Web site. Therefore, it is known as the breadcrumb or eyebrow navigation control. 80. Where is the ViewState information stored? The ViewState information is stored in the HTML hidden fields. 81. Which namespaces are necessary to create a localized application?
  19. 19. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 19 The System.Globalization and System.Resources namespaces are essential to develop a localized application. 82. What is the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control? You can select more than one HtmlInputCheckBox control from a group of HtmlInputCheckBox controls; whereas, you can select only a single HtmllnputRadioButton control from a group of HtmlInputRadioButton controls. 83. What is the difference between HTML and Web server controls? HTML controls are client-side controls; therefore, all the validations for HTML controls are performed at the client side. On the other hand, Web server controls are server-side controls; therefore, all the validations for Web server controls are performed at the server side. 84. Explain the AdRotator Control. The AdRotator is an ASP.NET control that is used to provide advertisements to Web pages. The AdRotator control associates with one or many advertisements, which randomly displays one by one at a time when the Web page is refreshed. The AdRotator control advertisements are associated with links; therefore, when you click on an advertisement, it redirects you to other pages. The AdRotator control is associated with a data source, which is normally an xml file or a database table. A data source contains all the information, such as advertisement graphics reference, link, and alternate text. Therefore, when you use the AdRotator control, you should first create a data source and then associate it with the AdRotator control. 85. What do you understand by the culture?
  20. 20. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 20 The culture denotes a combination of a language and optionally a region or a country. The contents of a Web page of a multilingual Web site are changed according to the culture defined in the operating system of the user accessing the Web page. 86. What is the difference between absolute expiration and sliding-time expiration? The absolute expiration expires a cached item after the provided expiration time. The sliding time does not expire the cached items because it increments the specified time. 87. What is the code-behind feature in ASP.NET? The code-behind feature of ASP.NET enables you to divide an ASP.NET page into two files - one consisting of the presentation data, and the second, which is also called the code-behind file, consisting of all the business logic. The presentation data contains the interface elements, such as HTML controls and Web server controls, and the code-behind contains the event-handling process to handle the events that are fired by these controls. The file that contains the presentation data has the .aspx extension. The code behind file has either the .cs extension (if you are using the programming language C#) or the .vb (if you are using the programming language Visual Basic .NET) extension. 88. How can you check if all the validation controls on a Web page are valid and proper? You can determine that all the validation controls on a Web page are properly working by writing code in the source file of the Web page using a scripting language, such as VBScript or JavaScript. To do this task, you have to loop across validators collection of pages and check the IsValid property of each validation control
  21. 21. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 21 on the Web page to check whether or not the validation test is successful. 89. Explain the validation controls. How many validation controls in ASP.NET 4.0? Validation controls are responsible to validate the data of an input control. Whenever you provide any input to an application, it performs the validation and displays an error message to user, in case the validation fails. ASP.NET 4.0 contains the following six types of validation controls: CompareValidator - Performs a comparison between the values contained in two controls. CustomValidator - Writes your own method to perform extra validation. RangeValidator- Checks value according to the range of value. RegularExpressionValidator - Ensures that input is according to the specified pattern or not. RequiredFieldValidator - Checks either a control is empty or not. ValidationSummary - Displays a summary of all validation error in a central location. 90. What is difference between a Label control and a Literal control? The Label control's final html code has an HTML tag; whereas, the Literal control's final html code contains only text, which is not surrounded by any HTML tag. 91. How many types of Cookies are available in ASP.NET? There are two types of Cookies available in ASP.NET: Session Cookie - Resides on the client machine for a single session until the user does not log out. Persistent Cookie - Resides on a user's machine for a period specified for its expiry, such as 10 days, one month, and never. The user can set this period manually.
  22. 22. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 22 92. What is the use of the Global.asax file? The Global.asax file executes application-level events and sets application-level variables. 93. What are the Culture and UICulture values? The Culture value determines the functions, such as Date and Currency, which are used to format data and numbers in a Web page. The UICulture value determines the resources, such as strings or images, which are loaded for a Web page in a Web application. 94. What is the difference between ASP session and ASP.NET session? ASP does not support cookie-less sessions; whereas, ASP.NET does. In addition, the ASP.NET session can span across multiple servers. 95. Which control will you use to ensure that the values in two different controls match? You should use the CompareValidator control to ensure that the values in two different controls match. 96. What is the difference between a page theme and a global theme? A page theme is stored inside a subfolder of the App_Themes folder of a project and applied to individual Web pages of that project. Global themes are stored inside the Themes folder on a Web server and apply to all the Web applications on the Web server. 97. What do you mean by a neutral culture?
  23. 23. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 23 When you specify a language but do not specify the associated country through a culture, the culture is called as a neutral culture. 98. What is the use of the <sessionState> tag in the web.config file? The <sessionState> tag is used to configure the session state features. To change the default timeout, which is 20 minutes, you have to add the following code snippet to the web.config file of an application: <sessionState timeout="40"/> 99. Can you post and access view state in another application? Yes, you can post and access a view state in other applications. However, while posting a view state in another application, the PreviousPage property returns null. 100. Which method do you use to kill explicitly a users session? The Session.Abandon() method kills the user session explicitly. 101. Which class is inherited when an ASP.NET server control is added to a Web form? The System.Web.UI.WebControls class is inherited when an ASP.NET server control is added to a Web form. 102. What events are fired when a page loads? The following events fire when a page loads: Init() - Fires when the page is initializing. LoadViewState() - Fires when the view state is loading. LoadPostData() - Fires when the postback data is processing. Load() - Fires when the page is loading. PreRender() - Fires at the brief moment before the page is displayed to the user as HTML.
  24. 24. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 24 Unload() - Fires when the page is destroying the instances of server controls. 103. Write three common properties of all validation controls. Three common properties of validation controls are as follows: ControlToValidate - Provides a control to validate ErrorMessage - Displays an error message IsValid - Specifies if the control's validation has succeeded or not Text - Displays a text for validation control before validation 104. What are navigation controls? How many navigation controls are there in ASP.NET 4.0? Navigation controls help you to navigate in a Web application easily. These controls store all the links in a hierarchical or drop-down structure; thereby facilitating easy navigation in a Web application. There are three navigation controls in ASP.Net 4.0. SiteMapPath Menu TreeView 105. What happens if an ASP.NET server control with event-handling routines is missing from its definition? The compilation of the application fails. 106. What are server-side comments? Server-side comments are included in an ASP.NET page for the purpose of documentations as shown in the following code snippet: <%--This is an example of server-side comments --%> The server-side comments begin with <%-- and end with --%>. 107. How can we provide the WebParts control functionality to a server control?
  25. 25. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 25 We can provide the WebParts controls functionality to a server control by setting the CreateWebPart property of WebPartManger. 108. How do you prevent a validation control from validating data at the client end? You can prohibit a validation control to validate data at the client side by setting the EnableClientScript property to False. 09. What is cross-page posting in ASP.NET? The Server.Transfer() method is used to post data from one page to another. In this case, the URL remains the same. However, in cross page posting, data is collected from different Web pages and is displayed on a single page. To do so, you need to set the PostBackUrl property of the control, which specifies the target page. In the target page, you can access the PreviousPage property. For this, you need to use the @PreviousPageType directive. You can access the controls of previous page by using the FindControl() method. 110. Which ASP.NET configuration options are supported in the ASP.NET implementation on the shared Web hosting platform? There are many ASP.NET configuration choices, which are not able to configure at the site, application, or child directory level on the shared hosting environment. Some options can produce security, performance, and stability problem to the server and therefore cannot be changed. The following settings are the only ones that can be changed in the web.config file(s) of your Web site: browserCaps clientTarget pages customErrors globalization
  26. 26. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 26 authorization authentication webControls webServices 111. Explain the Application and Session objects in ASP.NET. Application state is used to store data corresponding to all the variables of an ASP.NET Web application. The data in an application state is stored once and read several times. Application state uses the HttpApplicationState class to store and share the data throughout the application. You can access the information stored in an application state by using the HttpApplication class property. Data stored in the application state is accessible to all the pages of the application and is the same for all the users accessing the application. The HttpApplicationState class provides a lock method, which you can use to ensure that only one user is able to access and modify the data of an application at any instant of time. Each client accessing a Web application maintains a distinct session with the Web server, and there is also some specific information associated with each of these sessions. Session state is defined in the <sessionState> element of the web.config file. It also stores the data specific to a user session in session variables. Different session variables are created for each user session. In addition, session variables can be accessed from any page of the application. When a user accesses a page, a session ID for the user is created. The session ID is transferred between the server and the client over the HTTP protocol using cookies. 112. How will you differentiate a submaster page from a top-level master page? Similar to a content page, a submaster page also does not have complete HTML source code; whereas, a top-level master page has complete HTML source code inside its source file. 113. What are Web server controls in ASP.NET?
  27. 27. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 27 The ASP.NET Web server controls are objects on the ASP.NET pages that run when the Web page is requested. Many Web server controls, such as button and text box, are similar to the HTML controls. In addition to the HTML controls, there are many controls, which include complex behavior, such as the controls used to connect to data sources and display data. 114. What is the difference between a HyperLink control and a LinkButton control? A HyperLink control does not have the Click and Command events; whereas, the LinkButton control has these events, which can be handled in the code-behind file of the Web page. 115. What are the various ways of authentication techniques in ASP.NET? There are various techniques in ASP.NET to authenticate a user. You can use one of the following ways of authentication to select a built-in authentication provider: Windows Authentication - This mode works as the default authentication technique. It can work with any form of Microsoft Internet Information Services (IIS) authentication, such as Basic, Integrated Windows authentication (NTLM/Kerberos), Digest, and certificates. The syntax of Windows authentication mode is given as follows: <authentication mode="windows" /> Forms Authentication - You can specify this mode as a default authentication mode by using the following code snippet: <authentication mode="Forms"/> Passport - This mode works with Microsoft Passport authentication, as shown in the following code snippet: <authentication mode = "Passport"/> 116. What are the different ways to send data across pages in ASP.NET? The following two ways are used to send data across pages in ASP.NET:
  28. 28. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 28 Session Public properties 117. What does the WebpartListUserControlPath property of a DeclarativeCatalogPart control do? The WebpartListUserControlPath property sets the route of the user defined control to a DeclarativeCatalogPart control. 118. What do you mean by the Web Part controls in ASP.NET? The Web Part controls are the integrated controls, which are used to create a Web site. These controls allow the users to change the content, outlook, and state of Web pages in a Web browser. 119. What type of the CatalogPart control enables users to restore the Web Parts that have been removed earlier by the user? The PageCatalogPart control. 120. What is the use of web.config? What is the difference between machine.config and web.config? ASP.NET configuration files are XML-based text files for application-level settings and are saved with the name web.config. These files are present in multiple directories on an ASP.NET Web application server. The web.config file sets the configuration settings to the directory it is placed in and to all the virtual sub folders under it. The settings in sub directories can optionally override or change the settings specified in the base directory. The difference between the web.config and machine.config files is given as follows: <WinDir>Microsoft.NETFramework<version>configmachin e.config provides default configuration settings for the entire
  29. 29. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 29 machine. ASP.NET configures IIS to prohibit the browser directly from accessing the web.config files to make sure that their values cannot be public. Attempts to access those files cause ASP.NET to return the 403: Access Forbidden error. ASP.NET uses these web.config configuration files at runtime to compute hierarchically a sole collection of settings for every URL target request. These settings compute only once and cached across further requests. ASP.NET automatically checks for changing file settings and do not validate the cache if any of the configuration changes made. 121. Explain the concept of states in ASP.NET. State is quite an innovative concept in Web development because it eliminates the drawback of losing state data due to reloading of a Web page. By using states in a Web application, you can preserve the state of the application either at the server or client end. The state of a Web application helps you to store the runtime changes that have been made to the Web application. For example, as already described earlier, a change in the data source of the Web application might be initiated by a user when he/she selects and saves some products in the shopping cart. If you are not using states, these changes are discarded and are not saved. You may think that the whole concept of storing states is optional. However, under certain circumstances, using states with applications is imperative. For example, it is necessary to store states for Web applications, such as an e-commerce shopping site or an Intranet site of a company, to keep track of the requests of the users for the items they have selected on the shopping site or the days requested for vacation on the Intranet site. 122. Can we validate a DropDownList by RequiredFieldValidator?
  30. 30. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 30 Yes, we can validate a DropDownList by RequiredFieldValidator. To perform this validation, we have to set the InitialValue property of RequiredFieldValidator control. 123. List the features of the Chart control. The following are the features of the Chart control: Bounds a chart with any data source. Simple manipulation of chart data, such as copying, merging, grouping, sorting, searching, and filtering. Support many statistical and financial formulas for data analysis. Provide advanced chart outlook, such as 2-D, 3-D, lighting, and perspective. Support events and customizations. Includes interactivity with Microsoft AJAX. Supports AJAX Content Delivery Network (CDN). Lesson 01: Introduction to ADO.NET This lesson is an introduction to ADO.NET. It introduces primary ADO.NET concepts and objects that you will learn about in later lessons. Here are the objectives of this lesson: Learn what ADO.NET is. Understand what a data provider is. Understand what a connection object is. Understand what a command object is. Understand what a DataReader object is. Understand what a DataSet object is. Understand what a DataAdapter object is. Introduction ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file. For the purposes of this tutorial, we will look at ADO.NET as a way to interact with a data base.
  31. 31. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 31 Data Providers We know that ADO.NET allows us to interact with different types of data sources and different types of databases. However, there isn't a single set of classes that allow you to accomplish this universally. Since different data sources expose different protocols, we need a way to communicate with the right data source using the right protocol Some older data sources use the ODBC protocol, many newer data sources use the OleDb protocol, and there are more data sources every day that allow you to communicate with them directly through .NET ADO.NET class libraries. ADO.NET provides a relatively common way to interact with data sources, but comes in different sets of libraries for each way you can talk to a data source. These libraries are called Data Providers and are usually named for the protocol or data source type they allow you to interact with. Table 1 lists some well known data providers, the API prefix they use, and the type of data source they allow you to interact with. Table 1. ADO.NET Data Providers are class libraries that allow a common way to interact with specific data sources or protocols. The library APIs have prefixes that indicate which provider they support. Provider NameAPI prefixData Source Description ODBC Data Provider Odbc Data Sources with an ODBC interface. Normally older data bases. OleDb Data Provider OleDb Data Sources that expose an OleDb interface, i.e. Access or Excel. Oracle Data Provider Oracle For Oracle Databases. SQL Data Provider Sql For interacting with Microsoft SQL Server. Borland Data Provider Bdp Generic access to many databases such as Interbase, SQL Server, IBM DB2, and Oracle. An example may help you to understand the meaning of the API
  32. 32. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 32 prefix. One of the first ADO.NET objects you'll learn about is the connection object, which allows you to establish a connection to a data source. If we were using the OleDb Data Provider to connect to a data source that exposes an OleDb interface, we would use a connection object named OleDbConnection. Similarly, the connection object name would be prefixed with Odbc or Sql for an OdbcConnection object on an Odbc data source or a SqlConnection object on a SQL Server database, respectively. Since we are using MSDE in this tutorial (a scaled down version of SQL Server) all the API objects will have the Sql prefix. i.e. SqlConnection. ADO.NET Objects ADO.NET includes many objects you can use to work with data. This section introduces some of the primary objects you will use. Over the course of this tutorial, you'll be exposed to many more ADO.NET objects from the perspective of how they are used in a particular lesson. The objects below are the ones you must know. Learning about them will give you an idea of the types of things you can do with data when using ADO.NET. The SqlConnection Object To interact with a database, you must have a connection to it. The connection helps identify the database server, the database name, user name, password, and other parameters that are required for connecting to the data base. A connection object is used by command objects so they will know which database to execute the command on. The SqlCommand Object The process of interacting with a database means that you must specify the actions you want to occur. This is done with a command object. You use a command object to send SQL statements to the database. A command object uses a connection object to figure out which database to communicate
  33. 33. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 33 with. You can use a command object alone, to execute a command directly, or assign a reference to a command object to an SqlDataAdapter, which holds a set of commands that work on a group of data as described below. The SqlDataReader Object Many data operations require that you only get a stream of data for reading. The data reader object allows you to obtain the results of a SELECT statement from a command object. For performance reasons, the data returned from a data reader is a fast forward-only stream of data. This means that you can only pull the data from the stream in a sequential manner This is good for speed, but if you need to manipulate data, then a DataSet is a better object to work with. The DataSet Object DataSet objects are in-memory representations of data. They contain multiple Datatable objects, which contain columns and rows, just like normal database tables. You can even define relations between tables to create parent-child relationships. The DataSet is specifically designed to help manage data in memory and to support disconnected operations on data, when such a scenario make sense. The DataSet is an object that is used by all of the Data Providers, which is why it does not have a Data Provider specific prefix. The SqlDataAdapter Object Sometimes the data you work with is primarily read-only and you rarely need to make changes to the underlying data source Some situations also call for caching data in memory to minimize the number of database calls for data that does not change. The data adapter makes it easy for you to accomplish these things by helping to manage data in a disconnected mode. The data adapter fills a DataSet object when reading the data and writes in a single batch when persisting changes back to the
  34. 34. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 34 database. A data adapter contains a reference to the connection object and opens and closes the connection automatically when reading from or writing to the database. Additionally, the data adapter contains command object references for SELECT, INSERT, UPDATE, and DELETE operations on the data. You will have a data adapter defined for each table in a DataSet and it will take care of all communication with the database for you. All you need to do is tell the data adapter when to load from or write to the database. Summary ADO.NET is the .NET technology for interacting with data sources. You have several Data Providers, which allow communication with different data sources, depending on the protocols they use or what the database is. Regardless, of which Data Provider used, you'll use a similar set of objects to interact with a data source. The SqlConnection object lets you manage a connection to a data source. SqlCommand objects allow you to talk to a data source and send commands to it. To have fast forward-only read access to data, use the SqlDataReader. If you want to work with disconnected data, use a DataSet and implement reading and writing to/from the data source with a SqlDataAdapter. STORE PROCEDURE***************************************** A stored procedure is a pre-defined, reusable routine that is stored in a database. SQL Server compiles stored procedures, which makes them more efficient to use. Therefore, rather than dynamically building queries in your code, you can take advantage of the reuse and performance benefits of stored procedures. The following sections will show you how to modify the SqlCommand object to use stored procedures. Additionally, you'll see another reason why parameter support is an important part of the ADO.NET libraries.
  35. 35. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 35 Executing a Stored Procedure In addition to commands built with strings, the SqlCommand type can be used to execute stored procedures. There are two tasks require to make this happen: let the SqlCommand object know which stored procedure to execute and tell the SqlCommand object that it is executing a stored procedure. These two steps are shown below: // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "Ten Most Expensive Products", conn); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; While declaring the SqlCommand object above, the first parameter is set to "Ten Most Expensive Products". This is the name of a stored procedure in the Northwind database. The second parameter is the connection object, which is the same as the SqlCommand constructor used for executing query strings. The second command tells the SqlCommand object what type of command it will execute by setting its CommandType property to the StoredProcedure value of the CommandType enum. The default interpretation of the first parameter to the SqlCommand constructor is to treat it as a query string. By setting the CommandType to StoredProcedure, the first parameter to the SqlCommand constructor will be interpreted as the name of a stored procedure (instead of interpreting it as a command string). The rest of the code can use the SqlCommand object the same as it is used in previous lessons. Sending Parameters to Stored Procedures Using parameters for stored procedures is the same as using parameters for query string commands. The following code
  36. 36. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 36 shows this: // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "CustOrderHist", conn); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure cmd.Parameters.Add( new SqlParameter("@CustomerID", custId)); The SqlCommand constructor above specifies the name of a stored procedure, CustOrderHist, as its first parameter. This particular stored procedure takes a single parameter, named @CustomerID. Therefore, we must populate this parameter using a SqlParameter object. The name of the parameter passed as the first parameter to the SqlParameter constructor must be spelled exactly the same as the stored procedure parameter. Then execute the command the same as you would with any other SqlCommand object. A Full Example The code in Listing 1 contains a full working example of how to use stored procedures. There are separate methods for a stored procedure without parameters and a stored procedure with parameters. Listing 1: Executing Stored Procedures using System; using System.Data; using System.Data.SqlClient;
  37. 37. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 37 class StoredProcDemo { static void Main() { StoredProcDemo spd = new StoredProcDemo(); // run a simple stored procedure spd.RunStoredProc(); // run a stored procedure that takes a parameter spd.RunStoredProcParams(); } // run a simple stored procedure public void RunStoredProc() { SqlConnection conn = null; SqlDataReader rdr = null; Console.WriteLine("nTop 10 Most Expensive Products:n"); try { // create and open a connection object conn = new SqlConnection("Server=(local);DataBase=Northwind;Integra ted Security=SSPI"); conn.Open(); // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "Ten Most Expensive Products", conn); // 2. set the command object so it knows // to execute a stored procedure
  38. 38. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 38 cmd.CommandType = CommandType.StoredProcedure; // execute the command rdr = cmd.ExecuteReader(); // iterate through results, printing each to console while (rdr.Read()) { Console.WriteLine( "Product: {0,-25} Price: ${1,6:####.00}", rdr["TenMostExpensiveProducts"], rdr["UnitPrice"]); } } finally { if (conn != null) { conn.Close(); } if (rdr != null) { rdr.Close(); } } } // run a stored procedure that takes a parameter public void RunStoredProcParams() { SqlConnection conn = null; SqlDataReader rdr = null; // typically obtained from user // input, but we take a short cut string custId = "FURIB";
  39. 39. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 39 Console.WriteLine("nCustomer Order History:n"); try { // create and open a connection object conn = new SqlConnection("Server=(local);DataBase=Northwind;Integra ted Security=SSPI"); conn.Open(); // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "CustOrderHist", conn); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure cmd.Parameters.Add( new SqlParameter("@CustomerID", custId)); // execute the command rdr = cmd.ExecuteReader(); // iterate through results, printing each to console while (rdr.Read()) { Console.WriteLine( "Product: {0,-35} Total: {1,2}", rdr["ProductName"], rdr["Total"]);
  40. 40. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 40 } } finally { if (conn != null) { conn.Close(); } if (rdr != null) { rdr.Close(); } } } } The RunStoredProc method in Listing 1 simply runs a stored procedure and prints the results to the console. In the RunStoredProcParams method, the stored procedure used takes a single parameter. This demonstrates that there is no difference between using parameters with query strings and stored procedures. The rest of the code should be familiar to those who have read previous lessons in this tutorial. Summary To execute stored procedures, you specify the name of the stored procedure in the first parameter of a SqlCommand constructor and then set the CommandType of the SqlCommand to StoredProcedure. You can also send parameters to a stored procedure by using SqlParameter objects, the same way it is done with SqlCommand objects that execute query strings. Once the SqlCommand object is constructed, you can use it just like any other SqlCommand object as described in previous lessons. * Differences between ExecuteReader, ExecuteNonQuery AND ExecuteScalar ExecuteNonQuery ExecuteNonQuery method will return number of rows effected
  41. 41. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 41 with INSERT, DELETE or UPDATE operations. This ExecuteNonQuery method will be used only for insert, update and delete, Create, and SET statements. (Read More) ExecuteScalar Execute Scalar will return single row single column value i.e. single value, on execution of SQL Query or Stored procedure using command object. It’s very fast to retrieve single values from database. (Read More) ExecuteReader Execute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure using command object. This one is forward only retrieval of records and it is used to read the table values from first to last. (Read More) MVC What is MVC ? It is a software architecture developed by XEROX PARC in 1978 for smalltalk programming language. It is not created by Microsoft.It's Just Used by the Microsoft. MVC came to become a reality bcos we want to create a pattern of seperation of responsibilities. The idea behind pattern is the separation of information,and how each one of the pieces interact with each other. MVC-- Model-View-Controller Model is the Data View is the visualization of the data Controller takes input Requests Model is the main data of your application.so if you working with bank account then account number,name is your data.View is the visualization of data or presentation layer of our application.controller would be taking input from the user accessing model,data,business logic and then returning data to the view. so view can render the output.So This is MVC. What is about ASP.NET MVC4 ? It is Framework build by Microsoft with the MVC principles in
  42. 42. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 42 mind to makes the separation among,business logic,data and UI very strong. It's Really Feet well in web application.B'cos data and business logic are completely separate. Testability and maintainability are key here very well. Because of Separation we can easily test and maintain our application. The MVC interaction in ASP.NET When user enter some URL into a browser and that URL get routed by routing engine inside ASP.NET MVC 4 and the first stop is to controller. The controller then taking the request and if needed and go to the main model.Inside main model is data actually the business logic of our application and if needed retrieve data from database,persist data from the database.And return the controller whatever. The controller get that data from model and send view model to the view.so view layer is part of framework returning WEB PAGE to the User.. this is all about MVC4 application flow. Model-Views -Controller Model : Classes that represent the data of the application and tha use validation logic to enforce business rules for that data. Views : Template Files that your application uses to dynamically generate HTML responses. Controller : Classes that handle incoming browser requests,retrieve model data,and then specify view templates that return a response to the browser. SOAP.......................................................................................... ..........................
  43. 43. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 43 What is SOAP? SOAP stands for Simple Object Access Protocol SOAP is a communication protocol SOAP is for communication between applications SOAP is a format for sending messages SOAP communicates via Internet SOAP is platform independent SOAP is language independent SOAP is based on XML SOAP is simple and extensible SOAP allows you to get around firewalls SOAP is a W3C recommendation Why SOAP? It is important for application development to allow Internet communication between programs. Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic. A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this. SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages. SOAP (Simple Object Access Protocol) is a messaging protocol that allows programs that run on disparate operating systems (such as Windows and Linux) to communicate using Hypertext Transfer Protocol (HTTP) and its Extensible Markup Language (XML). Since Web protocols are installed and available for use by all major operating system platforms, HTTP and XML provide an at-hand solution that allows programs running under different operating systems in a network to communicate with each
  44. 44. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 44 other. SOAP specifies exactly how to encode an HTTP header and an XML file so that a program in one computer can call a program in another computer and pass along information. SOAP also specifies how the called program can return a response. Despite its frequent pairing with HTTP, SOAP supports other transport protocols as well. SOAP defines the XML-based message format that Web service-enabled applications use to communicate and inter-operate with each other over the Web. The heterogeneous environment of the Web demands that applications support a common data encoding protocol and message format. SOAP is a standard for encoding messages in XML that invoke functions in other applications. SOAP is analogous to Remote Procedure Calls (RPC), used in many technologies such as DCOM and CORBA, but eliminates some of the complexities of using these interfaces. SOAP enables applications to call functions from other applications, running on any hardware platform, regardless of different operating systems or programming languages. SOAP calls are much more likely to get through firewall servers, since HTTP is typically Port 80 compliant, where other calls may be blocked for security reasons. Since HTTP requests are usually allowed through firewalls, programs using SOAP to communicate can be sure that the program can communicate with programs anywhere. Some of the advantages of leveraging SOAP include: It is platform and language independent. SOAP provides simplified communications through proxies and firewalls, as mentioned above. It has the ability to leverage different transport protocols, including HTTP and SMTP, as well as others. Some disadvantages of leveraging SOAP include: SOAP is typically much slower than other types of middleware standards, including CORBA. This due to the fact that SOAP uses
  45. 45. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 45 a verbose XML format. You need to fully understand the performance limitations before building applications around SOAP. SOAP is typically limited to pooling, and not event notifications, when leveraging HTTP for transport. What's more, only one client can use the services of one server in typical situations. Again, when leveraging HTTP as the transport protocol, there tends to be firewall latency due to the fact that the firewall is analyzing the HTTP transport. This is due to the fact that HTTP is also leveraged for Web browsing, and many firewalls do not understand the difference between the use of HTTP within a Web browser, and the use of HTTP within SOAP. SOAP has different levels of support, depending upon the programming language supported. For example, SOAP support within Python and PHP is not as strong as it is within Java and .NET. WEB SERVICES .................................................................................................. ... Different books and different organizations provide different definitions to Web Services. Some of them are listed here. A web service is any piece of software that makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications to a web service. For example, a client invokes a web service by sending an XML message, then waits for a corresponding XML response. As all communication is in XML, web services are not tied to any one operating system or programming language--Java can talk with Perl; Windows applications can talk with Unix applications. Web services are self-contained, modular, distributed, dynamic applications that can be described, published, located, or invoked over the network to create products, processes, and supply chains. These applications can be local, distributed, or web-based. Web services are built on top of open standards such as TCP/IP, HTTP, Java, HTML, and XML.
  46. 46. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 46 Web services are XML-based information exchange systems that use the Internet for direct application-to-application interaction. These systems can include programs, objects, messages, or documents. A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer. This interoperability (e.g., between Java and Python, or Windows and Linux applications) is due to the use of open standards. To summarize, a complete web service is, therefore, any service that: Is available over the Internet or private (intranet) networks Uses a standardized XML messaging system Is not tied to any one operating system or programming language Is self-describing via a common XML grammar Is discoverable via a simple find mechanism Components of Web Services The basic web services platform is XML + HTTP. All the standard web services work using the following components SOAP (Simple Object Access Protocol) UDDI (Universal Description, Discovery and Integration) WSDL (Web Services Description Language) All these components have been discussed in the Web Services Architecture chapter. How Does a Web Service Work? A web service enables communication among various applications by using open standards such as HTML, XML, WSDL,
  47. 47. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 47 and SOAP. A web service takes the help of: XML to tag the data SOAP to transfer a message WSDL to describe the availability of service. You can build a Java-based web service on Solaris that is accessible from your Visual Basic program that runs on Windows. You can also use C# to build new web services on Windows that can be invoked from your web application that is based on JavaServer Pages (JSP) and runs on Linux. Example Consider a simple account-management and order processing system. The accounting personnel use a client application built with Visual Basic or JSP to create new accounts and enter new customer orders. The processing logic for this system is written in Java and resides on a Solaris machine, which also interacts with a database to store information. The steps to perform this operation are as follows: The client program bundles the account registration information into a SOAP message. This SOAP message is sent to the web service as the body of an HTTP POST request. The web service unpacks the SOAP request and converts it into a command that the application can understand. The application processes the information as required and responds with a new unique account number for that customer. Next, the web service packages the response into another SOAP message, which it sends back to the client program in response
  48. 48. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 48 to its HTTP request. The client program unpacks the SOAP message to obtain the results of the account registration process. JAVASCRIPT VS JQuery....................................................................................... .. JavaScript is a language. Example: JQuery like a foriegn language which is already built by Javascript which is unknown to you what kind of JS is written there, you are just using it. JQuery is a framework built with JavaScript to help JavaScript programmers who are doing common web tasks. Example: But if you goto a country where it is spoken, a guide can still help you along, making your journey easier. jQuery is one of many frameworks which provide help in areas that can be frustrating when writing plain JavaScript. If you use JavaScript, you need to write you own scripting which may take time. If you use Jquery, you need not to write much scripting which already exists in JQuery. Developers need to handle by writing their own Javascript code. JQuery is a multi-browser JavaScript library designed to simplify the client-side scripting of HTML. What is JavaScript? JavaScript is a scripting language that was designed for use within a web browser. Typically, JavaScript is used for interface interactions. Slideshows and other interactive components are typically done using JavaScript. JavaScript has many other uses as well. If you are familiar with using the Google email client Gmail, you have experienced the power of JavaScript firsthand. Many of the additional features and functionalities that make Gmail such a popular email solution are created using JavaScript.
  49. 49. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 49 The uses of JavaScript don’t stop there, however. JavaScript has also been used for server-side programming, game development, and even creating desktop applications. Years ago, JavaScript was popular but web developers were not entirely sold on the idea of using it simply because every web browser would render JavaScript content in a different manner. Newer standards now force all web browsers to implement JavaScript uniformly; saving developers time and frustration trying to debug code for a specific web browsing client. Dynamic content is the hot topic in web development right now. Dynamic content refers to content that constantly changes and adapts to specific users whenever possible. For example, JavaScript can be used to determine if a website visitor is using a computer or a mobile device before deciding whether or not to render the mobile version of the website. It’s these small things behind the scenes that create genuine value in using JavaScript to create dynamic web pages. You can learn more about creating dynamic web content using JavaScript in the JavaScript Basics I & II course. What is jQuery? Before jQuery was developed, web developers created their own custom frameworks in JavaScript. This allowed them to work around specific bugs without wasting time debugging common features. This led to groups of developers creating JavaScript libraries that were open source and free to use. JQuery is simply a specific library of JavaScript code. There are many other JavaScript code libraries such as MooTools, but jQuery has become the most popular because it is so easy to use and extremely powerful. While many web developers confuse JavaScript and jQuery as
  50. 50. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 50 two separate programming languages, it is important for you to realize that they are both JavaScript. The difference is that jQuery has been optimized to perform many common scripting functions and it does so while using fewer lines of code. You can learn more about using jQuery in your own web development endeavors in the jQuery for Beginners course. So Which One Should You Use? Professional web developers spend a lot of time debating whether JavaScript or jQuery is appropriate in a given situation. The truth is that there is no correct answer. Either option can be used to create the exact same effects, but often jQuery can do it with fewer lines of code. As a general rule, jQuery is sufficient for most web development projects. There will be some projects that require traditional JavaScript; however, these are few and far between as of late. Although jQuery maybe the better choice in most scenarios, as a novice web developer you should still take the time to learn both JavaScript and jQuery. Although using JavaScript exclusively can slow down project completion time significantly, it’s important to realize how JavaScript works and how it affects the Document Object Model (DOM). You can learn more about using Javascript effectively in Introduction to Javascript. Remember that the biggest difference between jQuery and JavaScript is that jQuery has been optimized to work with a variety of browsers automatically. Unfortunately, JavaScript still has some issues with cross-browser compatibility due to poor JavaScript implementation practices on the part of web browser developers. To see this difference in action, consider the following example that is designed to change the background color of a body tag
  51. 51. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 51 using jQuery and JavaScript respectively: jQuery $ (‘body’) .css (‘background’, ‘#ccc’); JavaScript Function changeBachground(color) { Document.body.style.background = color; } Onload=”changeBackground (‘red’);” Can you see how in a large, complex web development project it makes more sense to use jQuery? A single line of code accomplishes what it takes four lines of code to accomplish in JavaScript and this doesn’t even account for the extra time you might spend debugging this short piece of code to work across popular web browsers including Internet Explorer, Firefox, Chrome, and Safari. Is jQuery the answer to all of your scripting needs? For most projects – yes. For those few projects that require the specific functions only available in traditional JavaScript, you can quickly adapt your style to include JavaScript code when needed. Remember that although 99% of your web development projects will work perfectly fine using jQuery, there will be a small percentage that does require JavaScript. As a result, it would be wise to study both so you can transition between the two as needed to provide a better web development service to your clients. What JavaScript can do for
  52. 52. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 52 you........................................................................ Let’s take a step back and count the merits of JavaScript: JavaScript is very easy to implement. All you need to do is put your code in the HTML document and tell the browser that it is JavaScript. JavaScript works on web users’ computers — even when they are offline! JavaScript allows you to create highly responsive interfaces that improve the user experience and provide dynamic functionality, without having to wait for the server to react and show another page. JavaScript can load content into the document if and when the user needs it, without reloading the entire page — this is commonly referred to as Ajax. JavaScript can test for what is possible in your browser and react accordingly — this is called Principles of unobtrusive JavaScript or sometimes defensive Scripting. JavaScript can help fix browser problems or patch holes in browser support — for example fixing CSS layout issues in certain browsers. That is a lot for a language that until recently was laughed at by programmers favouring “higher programming languages”. One part of the renaissance of JavaScript is that we are building more and more complex web applications these days, and high interactivity either requires Flash (or other plugins) or scripting. JavaScript is arguably the best way to go, as it is a web standard, it is supported natively across browsers (more or less — some things differ across browsers, and these differences are discussed in appropriate places in the articles that follow this one), and it is compatible with other open web standards. JQuery....................................................................................... ...... jQuery is not a language, but it is a well written JavaScript code. As quoted on official jQuery website, "it is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web
  53. 53. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 53 development". Why jQuery? jQuery is very compact and well written JavaScript code that increases the productivity of the developer by enabling them to achieve critical UI functionality by writing very small amount of code. It helps to improve the performance of the application It helps to develop most browser compatible web page It helps to implement UI related critical functionality without writing hundreds of lines of codes It is fast It is extensible – jQuery can be extended to implement customized behavior Other advantages of jQuery are: No need to learn fresh new syntaxes to use jQuery, knowing simple JavaScript syntax is enough Simple and cleaner code, no need to write several lines of codes to achieve complex functionality Do I need to refer jQuery file both in Master page/base page/template page and content page? No, master page/base page/ template page basically helps to create consistent layout for the page in the application. In case you have referred the jQuery file in master page/base page/ template page that causes rendering the file in the browser, you do not need to refer jQuery file in the content page again. In summary, there should not be more than one <script> tag with jQuery file reference in the source code of the rendered web page in the browser. What is the difference between jQuery-x.x.x.js and jQuery.x.x.x min.js? In terms of functionality, there is no difference between the
  54. 54. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 54 jQuery-x.x.x.js and jQuery-x.x.x-min.js (also called minified version). However, this can play a vital role in the performance of the web page. How does it affect performance? jQuery-1.4.4.js file size is 178 KB as against its minified version jQuery-1.4.4-min.js that is only 76.7 KB in size. So when your page loads in the client’s browser if you are not using minified version, it loads 178 KB file that takes more time to load than 76.7 KB. Which Version of jQuery File Should Be Used? In most of the recent releases so far, the core functionality of jQuery remains the same, however some more cool and better features are added. Ideally, you should use the latest jQuery files available on the jQuery.com website. By doing this, you ensure that your earlier functionality will still work and you can use new features available as part of the new release. JSON and XML ...................................................................................... Key Characteristic Differences between XML and JSON Characteristic XML JSON Data types Does not provide any notion of data types. One must rely on XML Schema for adding type information. Provides scalar data types and the ability to express structured data through arrays and objects. Support for arrays Arrays have to be expressed by conventions, for example through the use of an outer placeholder element that models the arrays contents as inner elements. Typically, the outer element uses the plural form of the name used for inner elements. Native array support.
  55. 55. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 55 Support for objects Objects have to be expressed by conventions, often through a mixed use of attributes and elements. Native object support. Null support Requires use of xsi:nil on elements in an XML instance document plus an import of the corresponding namespace. Natively recognizes the null value. Comments Native support and usually available through APIs. Not supported. Namespaces Supports namespaces, which eliminates the risk of name collisions when combining documents. Namespaces also allow existing XML-based standards to be safely extended. No concept of namespaces. Naming collisions are usually avoided by nesting objects or using a prefix in an object member name (the former is preferred in practice). Formatting decisions Complex. Requires a greater effort to decide how to map application types to XML elements and attributes. Can create heated debates whether an element-centric or attribute-centric approach is better. Simple. Provides a much more direct mapping for application data. The only exception may be the absence of date/time literal. Size Documents tend to be lengthy in size, especially when an element-centric approach to formatting is used. Syntax is very terse and yields formatted text where most of the space is consumed (rightly so) by the represented data. Parsing in JavaScript Requires an XML DOM implementation and additional application code to map text back into JavaScript objects. No additional application code required to parse text; can use JavaScript's eval function. Learning curve Generally tends to require use of several technologies in concert: XPath, XML Schema, XSLT, XML Namespaces, the DOM, and so on. Very simple technology stack that is already familiar to
  56. 56. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 56 developers with a background in JavaScript or other dynamic programming languages. JSON……………………………………………………………………………… … JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. This week I want to cover a topic that I feel has become an important part of any developer’s toolkit: the ability to load and manipulate JSON feeds from other sites via AJAX. Many sites are sharing data using JSON in addition to RSS feeds nowadays, and with good reason: JSON feeds can be loaded asynchronously much more easily than XML/RSS. This article will cover the following: What is JSON? Why does JSON matter? How do we use JSON in a project? We’ll also use our newfound skills with JSON at the end of this project to build a quick app that loads photos from Flickr without requiring a page refresh. See the Demo | Download the Source WHAT IS JSON? JSON is short for JavaScript Object Notation, and is a way to store information in an organized, easy-to-access manner. In a nutshell, it gives us a human-readable collection of data that we can access in a really logical manner. Storing JSON Data As a simple example, information about me might be written in JSON as follows:
  57. 57. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 57 https://gist.github.com/2760279 This creates an object that we access using the variable jason. By enclosing the variable’s value in curly braces, we’re indicating that the value is an object. Inside the object, we can declare any number of properties using a "name": "value" pairing, separated by commas. To access the information stored in jason, we can simply refer to the name of the property we need. For instance, to access information about me, we could use the following snippets: https://gist.github.com/2760312 Storing JSON Data in Arrays A slightly more complicated example involves storing two people in one variable. To do this, we enclose multiple objects in square brackets, which signifies an array. For instance, if I needed to include information about myself and my brother in one variable, I might use the following: https://gist.github.com/2760314 To access this information, we need to access the array index of the person we wish to access. For example, we would use the following snippet to access info stored in family: https://gist.github.com/2760322 NOTE: This is beneficial if it will be necessary to loop through stored information, as it lends itself to a for loop with an automatically incrementing value. Nesting JSON Data Another way to store multiple people in our variable would be to nest objects. To do this, we would create something similar to the following:
  58. 58. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 58 https://gist.github.com/2760326 Accessing information in nested objects is a little easier to understand; to access information in the object, we would use the following snippet: https://gist.github.com/2760328 Nested JSON and arrays can be combined as needed to store as much data as necessary. WHY DOES JSON MATTER? With the rise of AJAX-powered sites, it’s becoming more and more important for sites to be able to load data quickly and asynchronously, or in the background without delaying page rendering. Switching up the contents of a certain element within our layouts without requiring a page refresh adds a “wow” factor to our applications, not to mention the added convenience for our users. Because of the popularity and ease of social media, many sites rely on the content provided by sites such as Twitter, Flickr, and others. These sites provide RSS feeds, which are easy to import and use on the server-side, but if we try to load them with AJAX, we run into a wall: we can only load an RSS feed if we’re requesting it from the same domain it’s hosted on. An attempt to load my Flickr account’s RSS feed via jQuery’s $.ajax() method results in the following JavaScript error: https://gist.github.com/2760335 JSON allows us to overcome the cross-domain issue because we can use a method called JSONP that uses a callback function to send the JSON data back to our domain. It’s this capability that makes JSON so incredibly useful, as it opens up a lot of doors that were previously difficult to work around. Difference between LINQ to SQL and Entity Framework...................................
  59. 59. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 59 LiNQ to SQL allow you to query and modify SQL Server database by using LINQ syntax. Entity framework is a great ORM shipped by Microsoft which allow you to query and modify RDBMS like SQL Server, Oracle, DB2 and MySQL etc. by using LINQ syntax. Today, EF is widely used by each and every .NET application to query to database. The difference between LINQ to SQL and EF is given below. LINQ to SQL Entity Framework It only works with SQL Server Database. It can works with various databases like Oracle, DB2, MYSQL, SQL Server etc. It generates a .dbml to maintain the relation It generates an .edmx files initially. The relation is maintained using 3 different files .csdl, .msl and .ssdl It has not support for complex type. It has support for complex type. It cannot generate database from model. It can generate database from model. It allows only one to one mapping between the entity classes and the relational tables /views. It allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables /views It allows you to query data using DataContext. It allows you to query data using EntitySQL, ObjectContext, DbContext. It provides a tightly coupled approach. It provides a loosely coupled approach. Since its code first approach allow you to use Dependency Injection pattern which make it loosely coupled . It can be used for rapid application development only with SQL Server. It can be used for rapid application development with RDBMS like SQL Server, Oracle, DB2 and MySQL etc. LINQ.......................................................... Linq stands for Language Integrated Query Instead of writing YAQL (yet another query language), MS
  60. 60. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 60 language developers provided a way to express queries directly in their languages (such as c# and vb). The techniques for forming these queries do not rely on the implementation details of the thing being queried, so that you can write valid queries against many targets (databases, in-memory objects, xml) with practically no consideration of the underlying way in which the query will be executed. Let's start this exploration with the parts belonging to the .Net Framework (3.5). Linq To Objects - examine System.Linq.Enumerable for query methods. These target IEnumerable<T>, allowing any typed loopable collection to be queried in a type-safe manner. These queries rely on compiled .Net methods, not Expressions. Linq To Anything - examine System.Linq.Queryable for some query methods. These target IQueryable<T>, allowing the construction of Expression Trees that can be translated by the underlying implementation. Expression Trees - examine System.Linq.Expressions namespace. This is code as data. In practice, you should be aware of this stuff, but don't really need to write code against these types. Language features (such as lambda expressions) can allow you to use various short-hands to avoid dealing with these types directly. Linq To Sql - examine the System.Data.Linq namespace. Especially note the DataContext. This is a DataAccess technology built by the C# team. It just works. Linq To Entities - examine the System.Data.Objects namespace. Especially note the ObjectContext. This is a DataAccess technology built by the ADO.Net team. It is complex, powerful, and harder to use than Linq To Sql. Linq To Xml - examine the System.Xml.Linq namespace.
  61. 61. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 61 Essentially, people weren't satisfied with the stuff in System.Xml . So MS re-wrote it and took advantage of the re-write to introduce some methods that make it easier to use LinqToObjects against Xml. Some nice helper types, such as Func and Action. These types are delegates with Generic Support. Gone are the days of declaring your own custom (and un-interchangable) delegate types. All of the above is part of the .Net Framework, and available from any .Net language (vb.net, c#, iron python, cobol.net ...). *LINQ********************************* Query (LINQ), is a component released within the .NET 3.5 Framework. It is one of the most powerful features of .NET 3.5. It serves the purpose of querying objects. LINQ comprises a series of operators, which are used to query, filter and project data in arrays, enumerable classes, relational databases and XML. In order to query data, the data needs to be encapsulated as an object. In case the data source is not an object, it first needs to be converted to an object in order for LINQ to query it. LINQ has its own Query Processing Engine. The information returned by a LINQ query is a collection of in-memory object which may be enumerated. The LINQ concept treats the data source as an Object, rather than a Database. So we may say, its an object that is queried. LINQ may query any type of data source, like: LINQ querying SQL (MS SQL Server supported). LINQ querying Datasets (Querying is possible on Datasets and DataTables) LINQ querying ORM Solution LINQ querying Objects (In-memory data may be queried) LINQ querying XML (Querying is possible on XML data source
  62. 62. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 62 LINQ supports querying to those objects that implement the IEnumerable Interface. ************************************************************************ ******* What is Entity Framework? Writing and managing ADO.Net code for data access is a tedious and monotonous job. Microsoft has provided an O/RM framework called "Entity Framework" to automate database related activities for your application. Microsoft has given the following definition of Entity Framework: The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects. The Entity Framework's ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals. Entity framework is an Object/Relational Mapping (O/RM) framework. It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in the database. Entity framework is useful in three scenarios. First, if you already have existing database or you want to design your database ahead of other parts of the application. Second, you want to focus on your domain classes and then create the database from your domain classes. Third, you want to design your database schema on the visual designer and then create the database and classes.
  63. 63. ASP.net with C# Interview Question & Answers 2015 Prepared By : Kundan Page 63 The following figure illustrates the above scenarios. Advantage of Entity Framework 1. EF reduce code by creating Model instead of create class to access data. 2. Easy and fast Functionality for select, Insert, update ,delete and other CRUD operation. 3. Data access code is under source control. If any Database Modification required, no need to change Data access logic. You have to just change model or business object. 4. Easy to manage relationship between tables. 5. Faster Development approach then ADO.NET. 6. Code is also usually much neater and more maintainable 7. Conceptual model can be represented in a better way. *************************LINQ*********************************** 1. What is Language Integrated Query (LINQ)? LINQ is a programming model that is the composition of general-purpose standard query operators that allow you to work with data, regardless of the data source in any .NET based programming language. It is the name given to a set of technologies based on the integration of query capabilities into any .NET language. 2. What are LINQ query expressions? A LINQ query, also known as a query expression, consists of a combination of query clauses that identify the data sources for the query. It includes instructions for sorting, filtering, grouping, or joining to apply to the source data. The LINQ query expressions syntax is similar to the SQL syntax. It specifies what information should be retrieved from the data source. 3. Write the basic steps to execute a LINQ query. The following are the three basic steps to execute a LINQ query:

×