ASP.NET Interview Questions with Answers

33 comments
In this series of tutorial I will list some important .net interview questions with answers which are generally asked in written or verbal technical interviews from .net developers by majority of IT Companies. These ASP.Net interview questions are suitable for candidates who are applying as a fresher  or having more than 2 years, 3 years, 4 years or 5 Years of experience. Most of the questions which are given here are those which are asked in real interviews and some of the questions are those which are more likely to be asked by many Software Companies during selection process. All readers are advised to study the detailed answers of listed questions here from other sites as well so they get clear concept of each question.

I also request readers to provide more questions which are asked from them when they applied for the job in an IT Company , so it can benefit others as well.

1. What are maximum number of cookies per website in asp.net web application?

Answer: 20 cookies

2. Which Namespace is used for custom controls in asp.net?
Answer: System.Web.UI.Control

3. Which namespace used for session state in asp.net?
Answer: System.Web.SessionState

4. Which is not method of Response object:
(a)Respone.Buffer()
(b) Response.End()
(c) Response.Clear()
(d) Response.Execute()

Answer: Response.Execute()

5. Does repeater has automatic paging?
Answer :No

6. Does grid view control in asp.net 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 asp.net controls to maintain its state during postbacks( Http Request). 

10. What is Response.End() in asp.net?

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 asp.net?

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 asp.net.

Answer: System.Web.Services

16. Namespace for WCF services in asp.net.

Answer: System.ServiceModel

17. Namespace used for SqlConnection in asp.net.

Answer: System.Data.SqlClient

18. Namespace for List in asp.net.

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 asp.net?

Answer: System.Web

21. Namespace used for asp.net 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 asp.net?

Answer: System.Net.Mail namespace is used to send email. This namespace contain classes such as MailMessage, SmtpClient etc.

23. Difference between System.Web.Mail and System.Net.Mail namespace.

Answer: Both namespace used to send email in asp.net application. System.Web.Mail namespace used in .Net Framework 1.0 while System.Net.Mail is used in .Net Framework 2.0 and higher. System.Net.Mail namespace has more functionality compared to System.Web.Mail namespace.

Web.Configuration Interview Questions:

1.Can an asp.net application have more than one Web.Config File?
Answer: Yes a web application can have more than one web.config files.

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

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

4. How do you specify connection string in Web.config file?
Answer: <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Data Source=Server Name;Initial Catalog=Database Name;User ID=sa;Password=123"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

5. 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());

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

Syntax: <appSettings>
              <add key="test" value="This is testing value"/>
       </appSettings>

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

8. How to specify session time out in web.config?
Answer: : Default session timeout is 20 minutes for a web application. You can change session time in <sessionState> tag.

Syntax: <sessionState timeout="30"></sessionState>

Here timeout value is in minutes. 

9. What is meaning of <customErrors> 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) <customErrors mode="on">:Custom error are enabled. Custom Error would be shown to remote client and local host.
(b) <customErrors mode="off">: custom error disabled but asp.net error would be shown to local host and remote client.
(c) <customErrors mode="remoteonly">: This is default mode . Custom errors would be shown to the remote client while asp.net error would be shown to local host.

10. What is default authentication mode  in Web.config file?
Answer: Windows Authentication. <authentication mode="Windows/>

11. How to enable or disable view state in Web.config file.
Answer<pages enableViewState="false"></pages>: This will disable  viewstate.
             <pages enableViewState="true"></pages>: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: <system.net >.

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 <processmodel> 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?
Answer: <configuration></configuration>

18. How to redirect user from old website address to new website address?
Answer: <system.webServer>
   
      <httpRedirect destination="http://www.google.com" enabled="true">
       
       </httpRedirect>
  
   It will redirect all the url to www.google.com

  19. How to enable directory browsing in web.config file?
  Answer: <system.webServer>    
  <directoryBrowse enabled="true"/>
   </system.webServer>

 20. How to open default page using web.config file?
 Answer: <system.webServer>       
    <defaultDocument enabled="true">
<files>
      <add value="test.html"/>
    </files>
</defaultDocument>
  </system.webServer>

  21. How to redirect user to custom error page using web.config file?
  Answer:  <system.webServer>
  <httpErrors errorMode="Custom" >
    <remove statusCode="404" subStatusCode='-1' />
    <remove statusCode="500" subStatusCode='-1' />
    <error statusCode="404" path="/error.html" prefixLanguageFilePath="" responseMode="ExecuteURL"  />
    <error statusCode="500" path="/error.html" prefixLanguageFilePath="" responseMode="ExecuteURL" />  
  </httpErrors>
  </system.webServer>

  22. How to increase default file upload size limit in web.config file?
  Answer: <configuration>
   <system.web>
    <httpRuntime maxRequestLength="enter limit in kb" />
  </system.web>
</configuration>
The defualt file upload size is 4MB.

ADO.Net Interview Questions with Answers:

1. What is ado.net?
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 ado.net?
Answer: In ado.net there are different data provider to connect with particular type of database. The list of data provider in ado.net is as follow:
(a) Ado.net 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 ado.net?
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 ado.net?
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 ado.net?
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()

18. In which namespace ConnectionStrings property comes under?
Answer: System.Configuration












33 comments:

  1. I really love reading and following your post as I find them extremely informative and interesting. This post is equally informative as well as interesting . Thank you for information you been putting on making your site such an interesting. I gave something for my information. Interview Preparation

    ReplyDelete
  2. I think its good document for interview preparation keep it up.

    ReplyDelete
  3. Thanks for sharing such informative article.
    Regards,
    .Net Training in Chennai

    ReplyDelete
  4. Thank for sharing an highly informative post.. It will helpful for the beginners to enrich their knowledge.

    Regards

    Internship in Chennai

    ReplyDelete
  5. nice and really helpful article to everyone... thanks for sharing.
    apple-ios training in chennai

    ReplyDelete
  6. Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision.
    informix training in chennai

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. • Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision..
    websphere training in chennai

    ReplyDelete
  10. • Its really helpful for me. Suppose if anyone want to find real time coaching center.recently i did some blog may visit..
    microstrategy training in chennai

    ReplyDelete
  11. very informative & stunning interview hacking. keep sharing Best ASP .Net Training in Chennai

    ReplyDelete
  12. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  13. Hi, the information you provided here is very informative and useful for me. If anyone interested to learn AngularJS Training reach GangBoard. MSBI Training | Hadoop Training

    ReplyDelete
  14. The interview questions shared are very much useful Thanks for sharing it
    Hadoop Training in Chennai

    ReplyDelete
  15. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp software in chennai.

    ReplyDelete
  16. thank you for such a great article with us. hope it will be much useful for us. please keep on updating..
    Web designing course in chennai

    ReplyDelete
  17. hi welcome to this blog. really you have post an informative blog. it will be really helpful to many peoples. thank you for sharing this blog.
    android training in chennai

    ReplyDelete
  18. wow.Bundle of question & answers.Thank you so much for sharing.
    Android Training in Chennai |
    Dot Net Training in Chennai

    ReplyDelete
  19. Really an amazing post..! By reading your blog post i gained more information.
    Bulk SMS Chennai
    Internet Marketing Company Chennai

    ReplyDelete
  20. The dotnet interview questions shared are very much useful My sincere thanks for sharing this post and please continue to share this post
    Dot Net Training in Chennai

    ReplyDelete