This article will be a quick reference for the list of frequently asked ASP.NET Interview Questions and Answers with brief concepts and required code samples.
Having a good practical knowledge is not enough to crack technical interviews, at times. You should be well prepared on certain concepts to answer exactly to the point and make the impression.
This article contains a set of most commonly asked ASP.NET interview questions.Keep reading.
1. What is ASP? What is ASP.NET? What is the difference Between ASP & ASP.NET
ASP is acronym for Active Server Pages which is also identified as Classic ASP.
ASP is a server-side programming technology from Microsoft.
ASP is used for creating dynamic Web pages, which presents dynamic data from the database etc.
ASP pages require Internet Information Server(IIS)
The Web pages made using ASP program can access, ActiveX Data Objects (ADO) for accessing the database.
Simple Mail Transfer Protocol (SMTP) for e-mail, Component Object Model (COM) for distributed computing.
ASP is realized by using a dynamic-link library (asp.dll) which gets invoked by the IIS server
2. What is ViewState in ASP.NET?
View State is the mechanism in ASP.NET to retain the state of objects between postbacks. Viewstate is hidden fields in the form.The state of the objects are stored in this hidden field from client side and send to the server. During postback (subsequent request) the state of the objects are restored by using the stored ViewState data.
Syntax of the ViewState field can be seen as
3. What is the difference between Server.Transfer and Response.Redirect?
Both Response.Redirect and Server.Transfer are used to transfer user from a requested page to another page.
When Response.Redirect is done a fresh request is initiated from client to server for redirecting to a page.so there is an additional round trip in Response.Redirect.Since the redirect request is from the client side, after redirection we can see the new URL in Browser.
In the case of Server.Transfer, transfer of one page to another happens directly from the server without any round trip.Here the URL in browser remains the same.
4. What are the types of Authentication in ASP.NET?
There are 4 different types of authentication in ASP.NET. They are
Windows based authentication
Anonymous access (None)
The authentication mode is normally set in web.config file or machine.config file .
See the XML file config section for authentication as below,
<!-- mode=[Windows|Forms|Passport|None] -->
<authentication mode="Forms" />
1. Forms-based authentication (Form authentication)
As like a conventional login style, Form-based authentication accepts the user login credentials through a form.This form is normally a Web page in HTML format.The config file should be updated as below,
<authentication mode="Forms" />
2. Windows based authentication (Windows authentication)
Windows based authentication uses the existing Windows active directory accounts for authenticating the users.
This type of ASP.NET authentication is mostly used in intranet applications used within the organization, wherein all the users going to access the application have valid Windows accounts.
authentication tag in Web.config is updated as,
<authentication mode="Windows" />
3. Passport authentication
Another type of ASP.NET authentication mechanism is Passport authentication.In Passport based ASP.NET authentication, a service from Microsoft called Passport is used.
Passport is a centralized directory of user details.The websites opting for Passport Authentication can access the centralized passport service for authenticating users to their application.
Passport authentication mode is set as,
<authentication mode="Passport" />
4. Anonymous access (No Authentication)
In Anonymous type of authentication, there is normally free access to the application.Means authentication is explicitly disabled by setting authentication mode="None", so that anonymous users can access your application.
Set authentication mode as none below,
<authentication mode="None" />
5. What are Session state modes in ASP.NET?
For retaining session data across pages, ASP.NET supports different session state modes with respect to the available options for session data storage.
The available session state modes in ASP.NET are,
- In-Process Mode (InProc)
- SQL Server
InProc (In-Process Mode):
This Session state mode InProc is the default session state mode in ASP.NET.
As the name says, in-process mode stores session state values in the same process area. That means the session values and related variables are stored within web server memory.
In the Web.Config file of the application, the session state mode is mentioned as below.The session state timeout to be set as per your application demand.
<sessionState mode="InProc" timeout="20" />
In StateServer mode, the session state is stored in a service called ASP.NET state service.
StateServer mode ensures that session state will be retianed if the Web application is restarted
since the state server is separate from the ASP.NET worker process and IIS worker pool.
Hence the session state can be accessed by all Web servers in the Web farm.
<sessionState mode="StateServer" stateConnectionString="tcpip=SampleStateServer:42424"
In SQLServer mode, SQL Server database is used to store session state. Since outside process, it ensures that session state won't be lost even if the Web server gets restarted. Also by SQLServer mode, session state will be available to other Web servers in a Web farm.
In Web.config file, We have to specify the session state mode within the <configuration> element as below,
Since the mode is SQLServer, respective SQL Server connection string to be mentioned.
<sessionState mode="SQLServer" sqlConnectionString="Integrated Security=SSPI;data
In this session state mode, you can specify a custom storage resource for storing session state data.If using this mode you should explicitly specify the type of the session state storage provider.We can specify the storage provider by specifying the sub-element of the sessionState element
Need to specify the session state mode as like,
<sessionState mode="Custom" customProvider="OdbcSessionProvider">
<add name="OdbcSessionProvider" type="Samples.AspNet.Session.OdbcSessionStateStore"
connectionStringName="OdbcSessionServices" writeExceptionsToEventLog="false" />
In off mode session state are disabled and no session states are stored.
6. What is Global.asax? Why Global.asax is needed?
The Global.asax file is a top level file in an ASP.NET application which contains ASP.NET application level events. Hence global.aspx is also known as the ASP.NET application file.The Global.asax file is in the root directory of an ASP.NET application.Users can not access global.asax file.
Global.asax contains Application level events and session level events such as ,
Application_End() and many more.
As the name says these events are not fired on each and every request.They are fired only on specific events such as application start, session start, application end etc.
But there are some events in global.asax file which are fired on every request.Such as,
7. What are the different types of Validation controls in ASP.NET?
The validation controls ensure that the users enter correct data format.User inputted data is validated by the respective validator controls to avoid wrong data entry.Validation can happen on both client side and server side.
Following are the supported validation controls in ASP.NET,
This validator is attached to controls which are mandatory to have a value assigned.So if a user leaves the field empty this RequiredFieldValidator triggers error.
Validates that the user entered data is within the permissible range, If not raises an error message.
Compares the value inputted in one control with a value of another control or with a constant value.For comparing a comparison operator to be specified, such as Equal, NotEqual, LessThan, LessThan Equal etc.
Validates with the regular expression to ensure the user data is in the expected format.For example EmailID, website URL etc have a specific format and user must enter the same format.
Using CustomValidator control developer can specify custom validations apart from the above.Custom validation routines can be defined for validations at the client side and the server side.
This is not actually a control for validation.ValidationSummary control is used to display a consolidated error message list, instead of displaying individual messages for all failed validations.