Asp.Net Interview Questions (Part-1)

What are the types of ASP Objects?

You can create various type of object in ASP

  1. Response Object
  2. Application Object
  3. Request Object
  4. Session Object
  5. Server Object
  6. Error Object
  7. FileSystem Object
  8. File Object
  9. ADO Object
  10. Drive Object

List all different types of directives in Asp.Net?

  1. @ Assembly
  2. @ Control
  3. @ Implements
  4. @ Import
  5. @ Master
  6. @ MasterType
  7. @ OutputCache
  8. @ Page
  9. @ PreviousPageType
  10. @ Reference
  11. @ Register

What's the use of Response.Output.Write()?

Response.output.write() is used to display the formatted text.

Can you programmatically access IIS configuration settings?

Yes. By using ASP or scripts, you can create your own applications for remotely administering your IIS server. You can use Active Directory Service Interfaces (ADSI), WMI, or COM interfaces to configure IIS programmatically.

Can you have a web application running without web.Config file?

Yes. You can run asp.net application without web.config file. If you are not configure any settings in web.config file then it will take machine.config file for default configurtaons. However, it will not allow user to debug, even if you are running it in debug mode.

Which namespace is used to implement debug and trace methods?

The Systems.Diagnostics namespace includes Trace and Debug classes.

Which namespaces are used for data access?

The System.Data namespaces contain classes for accessing and managing data from diverse sources.

How can I configure ASP.NET that are running on a remote machine?

You can use Visual Studio remote debugger . Install the remote debugging components on the remote computer and launch the Remote Debugging Monitor (msvsmon.exe) when you start debugging.

Where the assembly is stored in asp.net?

Private assemblies are stored in project's bin folder to use in that particular project, whereas public or shared assemblies are stored in GAC(global assembly cache) so that it is available to every project.

What is the size of the session ID?

The ASP.NET session identifier is a randomly generated number encoded into a 24-character string consisting of lowercase characters from a to z and numbers from 0 to 5.

How to access session variables from any class in ASP.NET?

Access the Session via the threads HttpContext:

System.Web.HttpContext.Current.Session["loginId"]

What are the different Session state modes available in ASP.NET?

  1. InProc mode - which stores session state in memory on the Web server. This is the default.

  2. StateServer mode - which stores session state in a separate process called the ASP.NET state service

  3. SQLServer mode - stores session state in a SQL Server database.

  4. Custom mode - which enables you to specify a custom storage provider.

  5. Off mode - which disables session state.

How long the items in ViewState exists?

ViewState exists till your current page exists. This includes postbacks. Viewstate become nothing once it redirects or transfer to another page.

Does viewstate expire?

No. Viewstate itself does not expire. ViewState is kept as part of the PostBack process. Since it's posted back in a form, it can be reconstituted any time. It is important to note that, ViewState is stored in the Session so if your Session expires, the ViewState will be lost.

Which object encapsulates state or data of the client?

Session object.

Where is the ViewState information stored?

Viewstate is stored on page it self in encoded form. You can use hidden variable to store data that will be used only on that page and View State Data is stored in Base64 String encoded format.

In which event of page cycle is the ViewState available?

ViewState is loaded into memory between init and load. In Page Init, only Partially gets loaded. In Page load,viewstate complete. So whole loading is available in Page load only.

Which is the only event provided by Cache object?

CacheItemRemoved event is the only event provided by Cache object.

Which delegate can be used to notify the application when items are removed from the cache?

onRemoveCallback is used to notify the application when items are removed from the cache.

How can we prevent browser from caching an ASPX page?

Response.Cache.SetNoStore();

What is the difference between page-level caching and fragment caching?

Page-level caching refers to the cache an entire page and the Fragment caching refers to the portion of a webpage such as caching User Controls

How to open a page in a new window?

You can use a Javascript in code behind to open a page in a new window.

Response.Write("<script> window.open('https://net-informations.com/','_blank'); </script>");

What is the default timeout for a Cookie?

The default Expires value for a cookie is not a static time, but it creates a Session cookie. Setting the Expires property to MinValue makes this a session Cookie , which is its default value. This will stay active until the user closes their browser/clears their cookies. You can override this as required.

How to turn off cookies for a page?

You don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting in web.config file
<sessionState cookieless="true" />

What is the default timeout for a Cookie?

The default Expires value for a cookie is not a static time, but it creates a Session cookie. Setting the Expires property to MinValue makes this a session Cookie , which is its default value. This will stay active until the user closes their browser/clears their cookies. You can override this as required.

How to turn off cookies for a page?

You don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting in web.config file.
<sessionState cookieless="true" />

How would you create a permanent cookie?

Set its Expires property equal to DateTime.maxValue , that means cookies never Expires.

How to turn off cookies for a page?

Cookie.Discard Property when set true will instruct the client application not to save the Cookie on the user's hard disk when a session ends.

What are ASP.NET Page Life Cycle Events?

  1. PreInit
  2. Init
  3. InitComplete
  4. PreLoad
  5. Load
  6. Control events
  7. LoadComplete
  8. PreRender
  9. PreRenderComplete
  10. SaveStateComplete
  11. Render
  12. Unload

How can you 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 to server or not.
if(!IsPostBack) { // code place here }

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.
Response.Redirect("newpage.aspx");

What is the difference between a page theme and a global theme?

Page theme applies to a particular web pages of the project. It is stored inside a subfolder of the App_Themes folder while Global theme applies to all the web applications on the web server. It is stored inside the Themes folder on a Web server.

How do we assign page specific attributes?

Page attributes are specified using the @Page directive.

What events will occur when a page is loaded?

  1. Page_PreInit
  2. Page_Init
  3. Page_InitComplete
  4. Page_PreLoad

What is Role-based security?

Role-based security allows you to partition your web site according to the "role" of the user.

Which method do you use to kill explicitly a user session?

  1. Session.Abandon()
  2. Session.Remove() - It will kill session for the specific user.
  3. Session.Clear() - To remove all keys with the session as well as you can also use it to remove specific keys from the session.

Is it possible to create web application with both webforms and mvc?

Yes. You have to include below mvc assembly references in the web forms application to create hybrid application.

System.Web.Routing System.Web.Abstractions System.Web.Mvc

What is RedirectPermanent in ASP.Net?

The Response.RedirectPermanent() method performs a permanent redirection from a requested URL to a specified URL.

You can use RedirectPermanent if the resource has been moved permanently and will no longer be accessible in its previous location. Most browsers will cache this response and perform the redirect automatically without requesting the original resource again.

What are the advantages of Passport authentication?

The advantages of Passport authentication are that the user doesn't have to remember separate user names and passwords for various Web sites and that the user can maintain his or her profile information in a single location. There is no real-time, server-to-server communication between participating Web sites and the central .NET Passport servers.