ASP.NET Exclusive Interview Questions and Answers (348) - Page 17

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

348 records found.

Get 650+ Questpond's Interview videos on discount

What are advantages of setting the culture dynamically at the thread level over creating separate Web applications for each culture?

1. All cultures share the same application code, so the application doesn’t have to be compiled and deployed for each culture.
2. The application resides at a single Web address, you don’t need to redirect users to other Web applications.
3. The user can choose from a full array of available cultures.
___Implements the logic necessary to carry out personalization actions.

NOTE: This is objective type question, Please click question title for correct answer.
We can use the _______________ command prompt utility to convert a resource file in the text format into the binary format

NOTE: This is objective type question, Please click question title for correct answer.
________ determines whether a given control is visible to an individual user or to all users.

NOTE: This is objective type question, Please click question title for correct answer.
What is the sequence in which ASP.NET page life cycle is executed ?

This is a great  and the most asked ASP.NET interview question. Out of 100 .NET interviews atleast 70 interviewer will ask this question. The answer is very simple but the problem with the answer is that developers forget the  sequence of ASP.NET page life cycle.


The best way to remember this answer is by remembering the word SILVER.


S (Well this word is just to make up the word , you can just skip this.)
I (Init)
L (Load)
V (Validate)
E (Event)
R (Render)




ASP.NET Interview question :- How do we write a HttpHandler ?

This is a simple a .NET Interview question .Its a two step process.


First create a class which implements Ihttphandler

public class clsHttpHandler : IHttpHandler
{


    public bool IsReusable
   
{
        get { return true;
}
    }


    public void ProcessRequest(HttpContext
context)
    {
       // Put
implementation here.
    }
}


 


Step 2 make a entry in the web.config file.


 

<httpHandlers>
<add verb="*" path="*.gif"
type="clsHttpHandler"/>
</httpHandlers>



 


ASP.NET interview question :- How do we write a HttpModule ?

Again a simple .NET Interview question Writing a HttpModule is a two step process.


Create a class which implements IhttpModule.


 

public class clsHttpModule : IHttpModule
{


    public void Init(HttpApplication
context)
    {
      
this.httpApp = context;
      
httpApp.Context.Response.Clear();
      
httpApp.AuthenticateRequest += new
EventHandler(OnAuthentication);
      
httpApp.AuthorizeRequest += new
EventHandler(OnAuthorization);
 ....
 ....
 ....
  

    }
    void OnAuthorization(object
sender, EventArgs a)
   
{
       
//Implementation
    }
    void
OnAuthentication(object sender, EventArgs a)
   
{
      

       
//Implementation
    }
   
}


Make a entry in the web.config file.


 

<httpModules>
<add name="clsHttpModule"
type="clsHttpModule"/>
</httpModules>


 


.NET/ASP.NET Interview Question -What are Authentication, Authorization and it's different types?

Authentication:  Who the user is? or Authentication is process of Identifying the user is valid or not from the database.
Authorization:    To Identify what kind of authority or rights does user has.


Different Types:


In ASP.NET there are three way to do Authentication and Authorization.


1)Windows Authentication:
                                    In this methadology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.


2)Forms Authentication:
                                   This is a cookie based authentication where user name and password stored on client machine as cookie files or they are sent to URL for every request. Form-based authentication presents the users with an HTML-based web page that prompts the user for credentials.In case browser doesnot support cookies then username and password passed via URL string for every request.


3)Passport Authentication:
                                     Passport authentication is based on passport website provided by the microsoft.So when user logins with credentials it will be reached to the passport website(i.e. hotmail,devhood,windows live etc) where authentication will happen.If authentication is successful it will return a token to your website.


Following is the video for Authentication and Authorization


Regards,




.NET/ASP.NET Interview Question - How to implement Authentication and Authorization?

In ASP.NET there are three way to do Authentication and Authorization.


Windows Authentication:
                             In this methadology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.

<authentication mode="Windows"> 
  <forms name="
AuthenticationDemo" loginUrl="logon.aspx" protection="All" path="/" timeout="30"
/>
</authentication>

Deny access to the anonymous user in the Aauthorization section as follows:

<authorization>
     <deny users ="?" />

</authorization>


Forms Authentication:
                             This is a cookie based authentication where user name and password stored on client machine as cookie files or they are sent to URL for every request.Form-based authentication presents the users with an HTML-based web page that prompts the user for credentials.In case browser doesnot support cookies then username and password passed via URL string for every request.

<authentication mode="Forms">
<forms name=" AuthenticationDemo"
loginUrl="logon.aspx" protection="All" path="/" timeout="30" />

</authentication>
<credential
passwordFormat=”SHA1”>
<username="admin"
password="admin">
</credential>


Deny access to the anonymous user in the Aauthorization section as follows:

<authorization>
    <deny users ="?"
/>
</authorization>


Passport Authentication:
                                Passport authentication is based on passport website provided by the microsoft.So when user logins with credentials it will be reached to the passport website(i.e. hotmail,devhood,windows live etc)where authentication will happen.If authentication is successful it will return a token to your website.

<authentication mode= "Passport"/>


Regards,




.NET/ASP.NET Interview Question -Difference between SessionState and ViewState?

SessionState and ViewState are used to store data value when an respective postback occurs.

SessionState is used to store Value till the user end's the session.
ViewState is used to store Value for the current page only and when we switch to other page the data value of the previous page is lost.

Session is Server type storage whereas View is a client type storage.

Session provide higher security as compared to View as the data value is stored on server side.

Regards,



.NET/ASP.NET Interview Question -What is Viewstate?

ViewState is a state management technique build in ASP.NET.
ViewState basically maintains the state of the pages between postbacks.
ViewState maintain the session within the same page.
ViewState allows the state of objects to be stored in a hidden field on the page.

Regards,




.NET/ASP.NET Interview Question -Why do we need Sessions?

HTTP is a stateless protocol; it can't hold the client information on page. In other words after every request and response the server does not remember the state, data and who the user was. If user inserts some information, and move to the next page, that data will be lost and user would not able to retrieve the information.So, Session provides that facility to store information on server memory.

Below is the diagram to understand in better manner.



In the above example, when the user request the IIS server for the Page1.aspx then the request is broadcasted to the user/client browser and the connection is broken, Now when the same user request the IIS server for the Page2.aspx then again the request is broadcasted to the user/client browser but this time again the same user is treated as a new user as the connection was broken by IIS server after displaying the Page1.aspx page.
Note:-
So every single time a new request is made the same user is treated as a new one, so in order to maintain this we need Sessions.

Regards,




.NET/ASP.NET Interview Question - What are different types of Validators?

A validator is a computer program used to check the validity or syntactical correctness of a fragment of code or text.


IN ASP.NET there are six different types of Validators.


Required Field Validator.
Regular Expression Validator.
Compare Validator.
Range Validator.
CustomValidator.
Validation Summary


RequiredFieldValidator:-Ensure that the control has a value to assign in it or user does not skip an entry.


For Example:- 

 <asp:Textbox id="txtMobileNumber" runat="server"></asp:Textbox>
 <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
 ControlToValidate="txtMobileNumber"
 ErrorMessage="Mobile Number is a required field."
 ForeColor="Red">
 </asp:RequiredFieldValidator>


RegularExpressionValidator:-Ensure that the value of the control matches the expression of validator that is specified.This type of validation enables you to check for sequence of character, such as e-mail address,telephone number,postal code and so on.


For Example:- 

 <asp:TextBox ID="txtE-Mail" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
 ControlToValidate="txtPassword"
 ErrorMessage="Please Enter a Valid E-Mail" 
 ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> // for internet E-Mail.
 </asp:RegularExpressionValidator>


CompareValidator:-Ensure that the value of one control should be equal to value of another control.which is commonly used in password,less than,greater than or equal to.


For Example:-

<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:TextBox ID="txtConfirmPassword" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" 
ControlToCompare="txtPassword" ControlToValidate="txtConfirmPassword"
ErrorMessage="Password does not match">
</asp:CompareValidator>


RangeValidator:-Ensures that the value of the control is in specified lower and upper boundaries or specified range.  You can check ranges within pairs of numbers, alphabetic characters.


For Example:- 

<asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtPassword"
ErrorMessage="RangeValidator" MaximumValue="5000"
MinimumValue="100">
</asp:RangeValidator>>


CustomValidator:-This control is used to perform user defined validations.


ValidationSummary:-This validator is used to displays a detailed summary on the validation errors that currently exist.


Regards,





.NET and ASP.NET interview question - Difference between Cache and Session?

Session are private to the user.
Cache are global to the application.

Sessions may change from user to user whereas a single
Cache will be maintained for the entire application.

The following code shows how you can declare Session and Cache.

Session["MySession"] = TextBox1.Text;// Here Session is declared.
Cache.Insert("MyCache", TextBox2.Text);// Here Cache is declared.


Regards,



.NET and ASP.NET interview question - Difference between Cache and Application?

Application and Cache both help to share global data and cache data across the users.but cache object is proactive and you can define dependency.In application object you can't define depenency.


Below is the code for declaring application and cache object.

CacheDependency objCacheDependency = new CacheDependency(Server.MapPath("Banner.txt"));

 
Cache.Insert("Banner", strBanner, objCacheDependency);
Application["Banner"] = "strBanner";


In the above code, for Cache object you can define dependency but in Application object you can't define dependency.when the banner file is changed the Cache object can be refreshed but the application remain static and holds the old text of banner file.


Regards


.NET/ASP.NET Interview Question - How to cache an ASP.NET page?

Output Cache is used to Cache an ASP.NET page.


Output Cache is called as directives.


The below diagram shows, how exactly the caching is done.



                               Diagram of Caching.


Caching can be done in three ways as followings.



  1. Cache the complete page.
  2. Cache the portion of the page.
  3. Cache the complete page but a portion is static.

The below diagram will give an idea of Caching different forms.



 


                           Different types of Caching.


The below code snippet shows how to Cache the complete page.

<%@ OutputCache Duration="20" Location="Server"  VaryByParam="none" %> 

To Cache the portion of the page.we have to add web user control page and the directive is placed at the top of user control page.(.ascx file).

<%@ OutputCache Duration="20" VaryByControl="LiveScore" VaryByParam="*"%>

Now, for Caching the complete page but a portion should be static. we have to add web user control page and later you can define the output cache in the source of the web user control page.


Regards,





.NET/ASP.NET Interview Question - How to Validate a Controls in ASP.NET page using JavaScript?

Let's see an Simple example to understand.


Assuming that we have a TextBox and Button on the ASP.NET page like below.

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return validate()" />


Now, Add the below code snippet on the page source.

<script language="javascript" type="text/javascript">
function ValidateTextBox()    
{
   if(document.getElementById("<%=txtName.ClientID%>").value == "")       
   {            
   alert("Name Field Cannot be Empty");
   document.getElementById("<%=txtName.ClientID%>").focus();
    return false;      
   }
    return true;
}
</script>


Once you have completed the above steps, just run the project and see the result.


Regards,




.NET/ASP.NET Interview Question - When to use Remoting and when to use WebService?

Remoting are basically used when we are sure that both Server and Client are based on .NET platform.


WebServices are used when the Server and Client are in different platform like .NET and Java etc.


Regards,




.NET/ASP.NET Interview Question - What is SOAP?

SOAP(Simple Object Access Protocol) is a standard XML format for communicating between Server and Client in WebServices.


The below diagram dipicts an simple request and response using SOAP.


SOA.png


Regards,




.NET/ASP.NET Interview Question - What is Remoting?

Remoting is a .NET technology where we can invoke objects which are lying on different server or different geographical location.
Below is the diagram shows the concept of Remoting.
 


In the above diagram, a client which is located in India want to access object of .NET class from the server which is located in US, So this can be done by Remoting.

Regards,



More ASP.NET Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories