Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

ASP.NET Interview Questions and Answers for Freshers and Experinced 2017

1. What is format of Web.Config File?
Answer:Xml format.

2. Does a directory can have multiple web.config files?
Answer: No , a directory can have single web.config file.

3. How do you specify connection string in Web.config file?
             connectionString="Data Source=Server Name;Initial Catalog=Database Name;User ID=sa;Password=123"
         providerName="System.Data.SqlClient" />

4. How do you read connection string from Web.Config File?
Answer: SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["name of connection string in web.config file"].ToString());

5..What is tag in Web.Config file?
Answer: : tag is used to specify key value value pair which can be accessed throughout the application.

6. How read app setting value from web.config file?
Answer: string myname = ConfigurationManager.AppSettings["SampleName"].ToString();

7. What is state management and types of state management?
Answer : State management maintains the information about the client towards the server.
Two types state management :
1. Client Side   2. Server Side
Client side can be classified into  Cookies, Query Strings, Hidden Fields, View State
Server Side can be classified into Session State, Application State, InProc, Out Proc, State Server, SQL Server.

What is CLR ?
CLR is a Common Language Runtime, that manages the execution of .Net Application and
manage services like Memory management, Debugging, Security, Garbage Collection.

What is CTS ?
CTS is a Commmon Type System provides set of common data types for all languages.

8. what is session? How to specify session time out in web.config?
Answer: :
Session is the duration of connectivity between client and server application.
Session varibles are used to store large amount of data  and used for server side state management.
Default session timeout is 20 minutes for a web application. You can change session time in tag.

9. What is meaning of tag in web.config?
Answer: CustomErrors can be used to specify what information would be shown if some un-handled error occur during the execution.
CustomError Mode can be of 3 types:
(a) :Custom error are enabled. Custom Error would be shown to remote client and local host.
(b) : custom error disabled but error would be shown to local host and remote client.
(c) : This is default mode . Custom errors would be shown to the remote client while error would be shown to local host.

10. What is default authentication mode  in Web.config file?
Answer: Windows Authentication.

11. How to enable or disable view state in Web.config file.
Answer: : This will disable  viewstate.
             :This will enable viewstate.

12. What are different type of SessionState mode in Web.config file?
Answer:(a) Custom
            (b) InProc
            (c) SqlServer
            (d) StateServer
            (e) Off

13. In which tag you can specify the email setting for your web application.
Answer: .

14. Does Web server need to be rebooted if any change is made in web.config file?
Answer: No , server is not need to be restarted if any change is made in web.config file. Only tag is the exception. Change made inside this tag are not implemented until the server is restarted.

15. What would happen if you try to open web.config file in browser?
Answer: IIS prevent web.config file to be browsed in any browser. If you try to open web.config file in browser error HTTP Error 403 would be returned.

16. Does tag of web.config file are case sensitive?
Answer: Yes tags contained in web.config file are case sensitive.

17. Which is the root tag of Web.Config file?

18. How to redirect user from old website address to new website address?
Answer:               It will redirect all the url to

  19. How to enable directory browsing in web.config file?
20. How to open default page using web.config file?



  21. How to redirect user to custom error page using web.config file?

 22. How to increase default file upload size limit in web.config file?

The defualt file upload size is 4MB.

Read more:

1. What is
Answer: ADO stands for AcitveX Data Object. ADO.Net is the part of .net framework , it contain classes to provide connectivity with  various data sources such as relational, xml and application data.

2. Which are the various data provider in
Answer: In there are different data provider to connect with particular type of database. The list of data provider in is as follow:
(a) provider for MSSQL connectivity: System.Data.SqlClient
(b) Data Provider for OLE DB :(System.Data.OleDb) can be used to connect with MSAccess database etc.
(c) Data Provider with Oracle Database: System.Data.OracleClient
(d) ODBC data provider: System.Data.Odbc

3. Name two main objects in ADO.Net?
Answer: (a) DataReader
              (b) DataSet

4. Which method of adapter is used to fill data in DataSet Object?
Answer: Fill() method.

5. Which namespace used for SqlDataAdapter class?
Answer: System.Data.SqlClient
6. Which namespace used for DataSet class?
Answer: System.Data.
7. What does SqlCommnad represent?
Answer: SqlCommand is contained in the namespace System.Data.SqlClient. It represent Sql Query or Stored Procedure to be executed against database.
8. What is DataSet in
Answer: DataSet represents in memory cache of data. It follows disconnected approach in which connection to database is kept open till data retrieved from database and later data can be accessed even if the connection to database is closed. A DataSet contain collection of 0 or more tables.
9. Explain DataReader in
Answer: Data Reader provide way of reading forward-only stream of rows from Database. DataReader is efficient while reading a large amount of data as it do not cache data in memory compared to DataSet. DataReader follows Connected approach in which connection must be kept open till the end of retrieval and access of data from database.
10. Which property is used to check  if DataReader contain rows or not?
Answer: HasRows .
11. Which method of DataReader used to read rows returned by query from database?
Answer: Read() method is used to read rows one by one from DataReader.
12. Explain adp.Fill() method of DataAdapter.
Answer: Fill() method of DataAdapter is used to populate DataSet with values.
13. Which are the different commands of DataAdapter in
Answer: The following are the commands used with DataAdapter:
(a) SelectCommand: Get or set Sql Statement or stored procedure used to select record in data source.
(b) DeleteCommand: Get or set Sql Statement or stored procedure to delete record from data set.
(c) InsertCommand: Get or set Sql Statement or stored procedure to insert new record in the data source.
(d) UpdateCommand: Get or set Sql Statement or stored procedure to update records in data source.
14. Which property of DataAdapter return columns count in a row?
Answer: FieldCount return number of column in current row.
15. Which method is used to get the name of specified column in DataReader?
Answer: GetName() method is used to get the name of column in data reader.
16. What is the difference between ExecuteScalar(), ExecuteReader() and ExecuteNonQuery() Methods?
Answer: ExecuteScalar() method will return single value after executing sql query or stored procedure.
ExecuteReader() method will return the set of rows from database after execution of stored procedure or sql query.
ExecuteNonQuery() method will return an integer for number rows affected after insert , update or delete operation on database.
17. Which is the default provider to access database ?
Answer: System.Data.SqlClient()

Please briefly explain ASP.NET Page life Cycle?

ASP.NET page passes through a series of steps during its life cycle. Following is the high-level explanation of life cycle stages/steps.

Initialization: Controls raise their Init event in this stage.Objects and variables are initializes for complete lifecyle of request.

LoadViewState: is a post back stage and loads the view state for the controls that enabled its view state property.

LoadPostBackData: is also a post back stage and loads the data posted for the controls and update them.

Load: In this stage page as well as all the controls raise their Load event. Till this stage all the controls are initialized and loaded. In most of the cases, we are coding this event handler.

RaisePostBackEvent: is again a postback stage. For example, it's raise against a button click event. We can easily put our code here to perform certain actions.

SaveViewState: Finally, controls state is saved in this stage before Rendering HTML.

Render: This is the stage where HTML is generated for the page.

Dispose: Lastly, all objects associated with the request are cleaned up.

For very detailed explanation of Page Life Cycle is explained here.

What is the difference between custom controls and user controls?

Custom controls are basically compiled code i.e. DLLs. These can be easily added to toolbox, so it can be easily used across multiple projects using drag and drop approach. These controls are comparatively hard to create.

But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly couple with respect to User Interface and code. In order to use across multiple projects, we need to copy and paste to the other project as well.

What is the concept of view state in ASP.NET?

As in earlier question, we understood the concept of postback. So, in order to maintain the state between postbacks, ASP.NET provides a mechanism called view state. Hidden form fields are used to store the state of objects on client side and returned back to server in subsequent request (as postback occurs).

Difference between Response.Redirect and Server.Transfer?

In case of Response.Redirect, a new request is generated from client-side for redirected page. It's a kind of additional round trip. As new request is generated from client, so the new URL is visible to user in browser after redirection.

While in case of Server.Transfer, a request is transferred from one page to another without making a round trip from client. For the end user, URL remains the same in browser even after transferring to another page.

Please briefly explain the usage of Global.asax?

Global.asax is basically ASP.NET Application file. It’s a place to write code for Application-level events such as Application start, Application end, Session start and end, Application error etc. raised by ASP.NET or by HTTP Modules.

There is a good list of events that are fired but following are few of the important events in Global.asax:

Application_Init occurs in case of application initialization for the very first time.

·         Application_Start fires on application start.
·         Session_Start fires when a new user session starts
·         Application_Error occurs in case of an unhandled exception generated from application.
·         Session_End fires when user session ends.
·         Application_End fires when application ends or time out.
What are the different types of Validation controls in ASP.NET?

In order to validate user input, ASP.NET provides validation server controls. All validation controls inherits from BaseValidator class which contains the common validation properties and methods like ControlToValidate,Enabled, IsValid, EnableClientScript, ValidationGroup,Validate() etc.

ASP.NET provides a range of validation controls:

·         RequiredFieldValidator validates compulsory/required input.
·         RangeValidator validates the range. Validates that input falls between the given range values.
·         CompareValidator validates or compares the input of a control with another control value or with a fixed value.
·         RegularExpressionValidator validates input value against a defined regular expression pattern.
·         CustomValidator allows to customize the validation logic with respect to our application logic.
·         ValidationSummary displays all errors on page collectively.
What are the types of Authentication in ASP.NET?

There are three types of authentication available in ASP.NET:

·         Windows Authentication: This authentication method uses built-in windows security features to authenticate user.
·         Forms Authentication: authenticate against a customized list of users or users in a database.
·         Passport Authentication: validates against Microsoft Passport service which is basically a centralized authentication service.
What are Session state modes in ASP.NET?

ASP.NET supports different session state storage options:

·         In-Process is the default approach. It stores session state locally on same web server memory where the application is running.
·         StateServer mode stores session state in a process other than the one where application is running. Naturally, it has added advantages that session state is accessible from multiple web servers in a Web Farm and also session state will remain preserved even web application is restarted.
·         SQLServer mode stores session state in SQL Server database. It has the same advantages as that of StateServer.
·         Custom modes allows to define our custom storage provider.
·         Off mode disables session storage.

What is Strong Name?
A. Strong Name (SN) is used to make the dll as the unique as:
SN -k fileName.dll

 CLR and DLR?
A. CLR (Common Language Runtime) is the utility in the .Net framework to run the application. It is the run-time engine which actually executes the application with many responsibilities like taking care of memory management, versioning, CasPol etc.
DLR is new with .Net 4.0 which is the Dynamic Language Runtime and used to run the application on the fly wherever required. CLR runs as statically while DLR runs dynamically.
12. In case more than one version of an installable is installed, which version is invoked by default?
A. By default the CLR will take and invoke the latest version of the dll and execute it accordingly. There could be the same name assemblies exists in the GAC but they will have different versions altogether for their uniqueness.
So while running the application, CLR takes the latest version assembly and use in the application.

13. What are Globalization and localization? How to implement them?
A. Globalization is the concept of developing the application in more than one language while the Localization is used for a particular language. Like if we develop the application in more than one language we need to create the resource files (.resx) by using System. Globalization and when we open the application in a particular language, then the localizations used to convert that application to the selected language.
14. What is assembly, GAC? Where they are physically located?
A. Assembly is the collection of classes, namespaces, methods, properties which may be developed in different language but packed as a dll. So we can say that dll is the assembly.
There are 3 types of assemblies- Private Assembly, Shared Assembly, and Satellite Assembly.
GAC (Global Assembly Cache)- When the assembly is  required for more than one project or application, we need to make the assembly with strong name and keep it in GAC or in Assembly folder by installing the assembly with the GACUtil command.

 Does repeater has automatic paging?
Answer :No

6. Does grid view control in support pagination?
Answer :Yes (set AllowPaging property to True)

7. Is it possible to set max length of text box control in code behind?
Answer :Yes.( textBox1.MaxLength = 5).

8. What is default value for EnableViewState Property of server control?
Answer: True

9. What is view State?
Answer: View state let the controls to maintain its state during postbacks( Http Request).

10. What is Response.End() in
Answer: Response.End() stop the execution of the page and raise the EndRequest Event.

11. By which web protocol a web service is accessible?
Answer: SOAP(Simple Object Access Protocol)

12. Which namespace is used for all server control in
Answer: System.Web.UI.WebControls

13. Namespace for ConnectionString property.
Answer: System.Configuration

14. Namespace for DataSet.
Answer: System.Data

15. NameSpace for WebServices in
Answer: System.Web.Services

16. Namespace for WCF services in
Answer: System.ServiceModel

17. Namespace used for SqlConnection in
Answer: System.Data.SqlClient

18. Namespace for List in
Answer: System.Collections.Generic.
19. Namespace for DbContext in Entity Framework.
Answer: System.Data.Entity
20. Which namespace used for Request, Response, Application and Server object in
Answer: System.Web
21. Namespace used for authentication such as Windows Authentication, Passport Authentication or Form Authentication.
Answer: System.Web.Security
22. Which namespace is used to send email using SMTP Protocol in
Answer: System.Net.Mail namespace is used to send email. This namespace contain classes such as MailMessage, SmtpClient etc.

What is the difference Grid View and between Data Grid (Windows)?
1) GridView Control Enables you to add sorting, paging and editing capabilities without writing any code.
2)GridView Control Automatically Supports paging by setting the ‘PagerSetting’ Property.The Page Setting Property supports four Modles
a. Numeric(by default)
b. Next Previous
c. NumericFirstLast
d. Next PreviousLast
3)It is Used in
4)GridView Supports RowUpdating and RowUpdated Events.
5)GidView is Capable of Pre-Operations and Post-Operations.
6)GridView Has EditTemplates for this control
7)It has AutoFormat
1)DataGid Control raises single Event for operations
2)DataGird Supports the SortCommand Events that occur when a column is Soted.
3)DataGrid Supports UpdataCommand Event that occurs when the UpdateButton is clicked for an item in the grid.
4)DataGrid is used in Windows GUI Application.
5)It doesnot have EditTemplates for this control
6)It doesnot have AutoFormat

What are the different levels of State management in ASP.NET?

use notes


use notes

How many types of memories are there in .net?
Ans: Two types of memories are there in .net stack memory and heap memory
Is it possible to set the session out time manually?
Ans: Yes we can set the session out time manually in web.config.

How many web.config files are there in 1 project?

Ans: There might be multiple web.config files for a single project depending on the hierarchy of folders inside the root folder of the project, so for each folder we can use one web.config file

What is boxing and unboxing concepts in .net?
Ans: Boxing is a process of converting value type into reference type
Unboxing is a process of converting reference type to value type.
What are the differences between value type and reference type?
Ans: Value type contain variable and reference type are not containing value directly in its memory.
Memory is allocated in managed heap in reference type and in value type memory allocated in stack. Reference type ex-class value type-struct, enumeration
Is it possible to host the website from desktop?
Ans: Yes
Why we go for page rendering in Asp.Net Page life cycle?
Ans: Browser understands an only html control that’s why in page rendering we will convert the aspx controls into html controls.

1)Web application or webapp is an application that is accessed via Web browser over a network such as the Internet or an intranet
2) It is a computer software application that is coded in a browser-supported language (such as HTML, ASP, PHP, Perl, Python etc.) and reliant on a common web browser to render the application executable.

5)Web applications are programs that used to run inside some web server (e.g., IIS) to fulfill the user requests over the http.

Windows Application

1)A program that is written to run under Microsoft's Windows operating system.
3) runs on personal computers and work stations.
4)window based app. need to be install on your machine to access.
5)windows applications (desktop) need to be installed on each client's PC.
6)Windows application runs faster than Webapplication.

What is the Extension of web Service ? .asmx

cookies are usually limited to 4096 bytes and you can't store more than 20 cookies per site.

default is 20 minutes but you can change in web.conifg

By default, the maximum size of a file to be uploaded to the server using the FileUpload control is around 4MB.

This value can be increased by modifying the maxRequestLength attribute in the web application's configuration file (web.config)

What is the difference between throw and throw ex?

What is the difference between view state and hidden field?

Ans: viewstate is secured hidden field is insecure
Viewstate will store large amount of data but hidden filed will store small amount of data.

What happens when I enter a URL in my browser and click enter?

You type in the URL and hit go. The browser needs to translate that URL into an IP address so it knows what computer on the internet to connect to (That URL is just there to make it easier for us humans - kinda like speed-dial for phone numbers I guess). So your browser will see if it already has the appropriate IP address cached away from previous visits to the site. If not, it will make a DNS query to your DNS server (might be your router or your ISP's DNS server) - see… for more on DNS. Once your browser knows what IP to use, it will connect to the appropriate webserver and ask for the page. The webserver then returns the requested page and your browser renders it to the screen.

The firewall will control connections to & from your computer. For the most part it will just be controlling who can connect to your computer and on what ports. For web browsing your firewall generally won't be doing a whole lot.

Your router (see ) essentially guides your request through the network, helping the packets get from computer to computer and potentially doing some NAT (see… ) to translate IP addresses along the way (so your internat LAN request can be transitioned onto the wider internet and back).

IP Addresses (see ) are unique addresses for computers that basically allow computers to find each other. Think of the IP address as a computer's well address or phone number, you've got to know someone's phone number before you can call them and you've got to know a computer's IP address before you can connect to it. Going back to the start - that's what those URLS and DNS make possible, you don't know John Doe's phone number so you look in the phone book; likewise your computer doesn't know's IP address so it looks in DNS.

Caching is a technique of persisting data in local memory for immediate request of , allowing incoming requests to be served from memory directly.

Benefits of Caching

The following are the benefits of using Caching

Faster page rendering

Minimization of database hits

Minimization of the consumption of server resources

Types of Caching

Caching in ASP.NET can be of the following types

Page Output Caching

Page Fragment Caching

Data Caching

Page Output Caching

This is a concept by virtue of which the output of pages is cached using an Output Cache engine and all subsequent requests are served from the cache. Whenever a new request comes, this engine would check if there is a corresponding cache entry for this page. If there is a cache hit, i.e., if the engine finds a corresponding cache entry for this page, the page is rendered from the cache, else, the page being requested is rendered dynamically.

This is particularly useful for pages that are static and thus do not change for a considerable period of time.

Page output caching can be implemented in either of the following two ways:

· At design time using the OutputCache directive

· At runtime using the HttpPolicy class

The following is the complete syntax of page output caching directive

Location="Any | Client | Downstream | Server | None"
VaryByCustom="browser |customstring"
VaryByParam="parameter" %>The following statement is used to implement output caching in an aspx page at design time. The directive is placed at the top of the .aspx page.

VaryByParam="none" %>
Page Fragment Caching

This allows specific portions of the page to be cached rather than caching the whole page. This is useful in situations where we can have a page that contains both static and dynamic content. The following code depicts how this can be accomplished.

VaryByControl="EmpID;DeptID" VaryByParam="*"%> This directive is placed at the top of any User Control (.axcx file).

Data Caching

The following code is an implementation of On-Demand caching. The method GetUserInfo checks to see if the data exists in the cache. If it is present, it is returned from the cache, else, the GetUserInfoFromDatabase method fills the DataSet from the database and then populates the Cache.

public DataSet GetUserInfo()
string cacheKey = "UserInfo";
DataSet ds = Cache[cacheKey] as DataSet;
if (ds == null)
ds = GetUserInfoFromDatabase();
Cache.Insert(cacheKey, ds, null, NoAbsoluteExpiration,
TimeSpan.FromHours(15),CacheItemPriority.High, null);
return ds;

DataSet GetUserInfoFromDatabase() {
// Usual code to populate a data set from thedatabase. This data set
// object is then returned.

23. What is a data set?
  A DataSet is an in memory representation of data loaded from any data source.

ExecuteNonQuery(): will work with Action Queries only (Create,Alter,Drop,Insert,Update,Delete).

Returns the count of rows effected by the Query.
Return type is int
Return value is optional and can be assigned to an integer variable.

ExecuteReader(): will work with Action and Non-Action Queries (Select) Returns the collection of rows selected by the Query.

Return type is DataReader.
Return value is compulsory and should be assigned to an another object DataReader.

ExecuteScalar(): will work with Non-Action Queries that contain aggregate functions.

Return the first row and first column value of the query result.
Return type is object.
Return value is compulsory and should be assigned to a variable of required type

This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

ASP.NET Interview Questions and Answers for Freshers and Experinced 2017


Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription