Kickstart your career with best deals on top training courses NY10 Click to Copy

ASP.NET Interview Questions

ASP.NET Core is a free and open-source framework which is widely adopted for its easy updates, high-speed performance, and command line application that allows it to execute, create, and host several applications, easy maintenance, and cross-platform capabilities. We have compiled a few questions and answers on ASP.NET which will help you to showcase your knowledge to your employer on concepts which lie around it. The following interview questions for ASP.NET will surely help you to prepare and qualify for your ASP Net Core developer role.

  • 4.8/5 Rating
  • 20 Question(s)
  • 30 Mins of Read
  • 5316+ Reader(s)

Beginner

1. Client side:

  1. Hidden Field
  2. ViewState
  3. Cookies
  4. Control State
  5. Query Strings

2. Server side:

  1. Session
  2. Application
  3. Cache

ViewState is a client-side state management mechanism in ASP.NET. It is a default technique used by ASP.NET to persist the value of the page and controls during postbacks.

In ASP.NET ViewState the values are encrypted and stored in a hidden field ( named _VIEWSTATE) on the page as an encoded Base64 string. By default, ViewState is sent to the client browser and then returned to the server in the form of a hidden input control on your page.

Advantages:

  • It works at client side so it doesn't put any load on the server 
  • Easy to implement
  • ViewState ensures security because it stores the data in encrypted format.

Disadvantages:

  • It can be performance overhead if we are going to store a larger amount of data because it is associated with page only.
  • Does not track across pages. ViewState information does not automatically transfer from page to page.
  • A good hacker can get the data very easily by decoding the value of the ViewState. One can’t store sensitive data in the ViewState.
  • It does not have any support for mobile devices.

If the application is storing a lot of data in ViewState it can affect the overall responsiveness of the page, thereby affecting performance since data is stored on the page itself in hidden controls.

The ideal size of ViewState should be less than 30% of the page size.

DeflateStream and GZipStream are the classes in ASP.NET that provides methods and properties to compress and decompress streams. Using these classes to compress ViewState will reduce its size to around 40%.

No. ViewState is base-64 encoded. Hence you cannot read ViewState. If you right click on the Page and View Source you will find __ViewState is base-64 encoded.

LoadViewState event occurs between InitComplete and PreLoad events.

Caching is a technique of storing frequently used data/information in memory, so that, when the same data/information is needed next time, it could be directly retrieved from the memory instead of being generated by the application.

  1. Page Output Caching:

It keeps a copy of the response that was sent to the client in memory and subsequent requests are then responded with the cached output until the cache expires, which incredibly improves the ASP.NET web application performance. It is implemented by placing an OutputCache directive at the top of the .aspx page at design time.

Example: <%@OutputCache Duration="10" VaryByParam= "Id"%>

  1. Page Fragment Caching:

Sometimes we might want to cache just portions of a page. For example, we might have a header for our page which will have the same content for all users.  To specify that a user control should be cached, we use the @OutputCache directive just like we used it for the page.

<%@OutputCache Duration=10 VaryByParam="None" %>

  1. Data Caching:

Data Cache is used to store frequently used data in the Cache memory. It's much efficient to retrieve data from the data cache instead of database or other sources. We need use System.Web.Caching namespace. The scope of the data caching is within the application domain unlike "session". Every user can able to access these objects.

Create:    Cache["Employee"] ="DatasetName";

Retrieve:   Dataset dsEmployee = (Dataset) Cache ["Employee"]

Output cache functionality is achieved using the OutputCache attribute in the ASP.NET page header. Below is the syntax:

<%@ OutputCache Duration="20" Location="Server" Vary By Param="state" Vary By Custom="minor version" Vary By Header="Accept-Language"%>

Vary By Param - Caches different versions depending on input parameters sent through HTTP POST/GET.

Vary By Header - Caches different versions depending on the contents of the page header.

Vary By Custom - Lets you customize the way the cache handles page variations by declaring the attribute and overriding the Get Vary By Custom string handler.

Vary By Control - Caches different versions of a user control based on the value of properties of ASP objects in the control.

Data Cache can be removed manually using:                                                            

Cache.Remove(String key); //We need to specify the cache name
  1. Required field Validator
  2. Range Validator
  3. Compare Validator
  4. Custom Validator
  5. Regular expression Validator
  6. Summary Validator

Cookie is a small piece of information stored on the client machine. This file is located on client machines "C:\Document and Settings\Currently_Login user\Cookie" path.  It is used to store user preference information like Username, Password, City and PhoneNo etc. on client machines. We need to import namespace called System.Web.HttpCookie before we use a cookie. 

  1. Persistent Cookies: Persistent Cookies are Permanent Cookies stored as a text file in the hard disk of the computer. They stay on your hard disk and can be accessed by web servers until they are deleted or have expired. 
  2. Non-Persistent Cookies: Non-Persistent cookies are temporary. The cookie which will be alive till that time until your browser is alive, as you will log out to your browser or close your browser, cookies will get expire and user information would also be lost. So they are browser dependent cookies. They are also called in-memory cookies and session-based cookies.

50 Cookies per domain, with a maximum of 4 KB per cookie (or even 4 KB in total). If you want to support most browsers, then do not exceed 50 cookies per domain and 4093 bytes per domain. That is, the size of all cookies should not exceed 4093 bytes.

Advantages:

  • Cookies are simple to use and implement.
  • Occupies less memory, do not require any server resources and are stored on the user's computer so no extra burden on the server.
  • We can configure cookies to expire when the browser session ends (session cookies) or they can exist for a specified length of time on the client’s computer (persistent cookies).
  • Cookies persist a much longer period of time than Session state.

Disadvantages:

  • Cookies are maintained at the client system, so they are not secure
  • A limited number of cookies are allowed for the website (Max 50)
  • A limited amount of data can be maintained (Max 4kb)
  • Only plain text can be maintained

  By using HttpCookie class object. After creating cookie it will be attached to Response Object to send it to the client.

 Ex: 

 HttpCookie cookie1=new HttpCookie ("Username","Ritu"); Response.Cookies.Add (cookie1);

A query string is an information sent to the server appended to the end of a page URL. It is a simple way to pass some information from one page to another. The information can be easily passed from one page to another or to the same page.

Advantages:

  • Easy to implement.
  • No server resources are required. The query string containing in the HTTP requests for a specific URL
  • Supported by all browsers.

Disadvantages:

  • Many browsers impose a 255 URL character limit which can limit their flexibility.
  • Query string data is visible to the user in URL so they are insecure. 

ASP NET Core developers are sought after by companies for their niche skill sets. These interview questions on ASP.NET will give you a fair idea of the questions which the interviewer asks during an ASP.NET interview. So, prepare well and good luck!

We can cache multiple response from a single web form by using any one of the attributes from VaryByParam, VaryByHeaders or VaryByCustom attributes.

Example: If we want display different country data on our page where we can choose country name from the drop down list. On SelectedIndexChanged event of the Drop down we have to write some logic to fetch the country data according to the selected value and display the data of the particular country. By setting the VaryByParam attribute to the dropdown will cache all the responses received from server on SelectedIndexChanged event of drop down. 

 <%@ OutputCache Duration="20" Location="Server" VaryByParam="countryDropDown%>
<aspx:DropDownList ID="countryDropDown" AutoPostBack="true" runat="server" 
        onselectedindexchanged=" countryDropDown _SelectedIndexChanged">
      <asp:ListItem Text="Germany" Value=" Germany "></asp:ListItem>
      <asp:ListItem Text="Singapore" Value=" Singapore "></asp:ListItem>
       <asp: ListItem Text="India" Value=" India "></asp: ListItem>
    </asp:DropDownList>

Description

ASP.NET Core is a free and open-source framework which is widely adopted for its easy updates, high-speed performance, and command line application that allows it to execute, create, and host several applications, easy maintenance, and cross-platform capabilities. It is a framework of the future and there is a huge demand for professionals in this field.
Won’t a set of detailed FAQs boost your confidence to crack your ASP.NET interview? We have compiled a few questions and answers on ASP.NET which will help you to showcase your knowledge to your employer on concepts which lie around it. The following interview questions for ASP.NET will surely help you to prepare and qualify for your ASP Net Core developer role.