ASP.NET Interview Questions and Answers (1544) - Page 24

Difference between Session object and Profile object in ASP.NET?

Profile
1.Profile object is persistent.
2.Profile object uses the provider model to store information.
3. Profile object is strongly typed.
4. Mostly used for anonymous users.

Session
1.Session object is non-persistant.
2.Session object uses the In Proc, Out Of Process or SQL Server Mode to store information.
3. Session object is not strongly typed.
4. Used for authenticated users.
What are the validation controls available in asp.net?

1.RequiredFieldValidator - Helps in ensuring that a value has been entered for a field.

2.CompareValidator - Checks if the value of a control matches the value of another controls or variable.

3.RangeValidator - Checks if the value entered in a control is in specified range of values.

4.RegularExpressionValidator - Checks if the value entered matches the regular expression that specified.

5.CustomValidator - The value entered is checked by a client-side or server side function created by us.

6.ValidationSummary - A List of all validation errors occurring in all the controls is created and can be displayed on the page.
What are the two levels of variable supported by Asp.net?

1.Page -Level Variables eg:-String,int,float.
2.Object-Level Variables eg:-Application Level,Session Level
Is it possible to apply theme to a Master page?

With reference to the following link:
http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx

If we add the theme attribute to the @ Master directive, the page will raise an error when it runs.

But we can apply themes by using the following approaches:-

1. As master pages is placeholder/templated and it is merged with the content page very early in the page execution life-cycle. The theme that is applied to the the content pageis applied to the master page as well.

2. If the site as a whole is configured to use a theme by including a theme definition in the pages element.

Hence there is no theme attribute in the @Master directive.
What is Cache Callback in Cache?

The cache object has dependencies e.g. it stores relationships to the file. Cache items remove the object when these dependencies change. For this we would need to simply execute a callback method whenever items are removed from the cache to add the items back in cache.

E.g.: We have a string variable string var="hello" and store it in cache. This item would be removed from the cache if value is changed from "hello" to "bye". In such a case we need to simply write a callback function which would add updated var back in cache as it’s been removed as a result of its dependencies changing.
What is Absolute and Sliding expiration in .NET?

These two are Time based expiration strategies.

Absolute Expiration: In this case the Cache expires at a fixed specified date or time.
E.g.: Cache. Insert ("ABC", ds, null, DateTime.Now.AddMinutes (1), Cache.NoSlidingExpiration);
The cache is set to expire exactly two minutes after the user has retrieved the data.

Sliding Expiration: The cache duration increases by the specified sliding expiration value every time the page is requested.
E.g.: Cache.Insert ("ABC", ds, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes (1));
Here ‘ds’ stands for Dataset.
What are resource files and explain the steps to generate a resource file?

The resource files are those files which are in XML format. They contain all the resources needed by an application. These files can be used to store string, bitmaps, icons, fonts etc.

Steps to generate a resource file:
a. Open the web page in the design view.
b. Click Tools
c. Select generate local resource
d. .resx file generated in the solution explorer
e. Type in the resources. The file contains the key and value pairs.
f. Save the file.
What is Shared (static) member?

# It belongs to the type but not to any instance of a type.
# It can be accessed without creating an instance of the type.
# It can be accessed using the type name instead of the instance name.
# It can't refer to any instance data.
Explain the aim of using EnableViewState property?

It allows the page to save the users input on a form across postbacks. It saves all the server side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server, the server control is recreated with the state stored in viewstate.
What are the different types of Session state managements available with in ASP.NET?

ASP.NET provides In-Process and Out-of-Process state management.

In-Process stores the session in memory on the web server.

Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service.

Out-of-Process state management requires that all objects stored in session are serializable.
Define Error Events?

ASP.NET supports events. When any unhandled exception occurs in an application, an event occurs, that events are called as Error Events.

ASP.NET is having two events to handle exceptions.
• Page_Error: This is page event and is raised when any unhandled exception occur in the page.
• Application_Error: This is application event and is raised for all unhandled exceptions in the ASP.NET application and is implemented in global.asax

The Error events have two methods to handle the exception:
• GetLastError: Returns the last exception that occurred on the server.
• ClearError: This method clear error and thus stop the error to trigger subsequent error event.
Why the exception handling is important for an application?

Exception handling is used to prevent application from unusual errors occurrences at the time of execution. If the exceptions are handled properly, the application will never get terminated abruptly.
What is Session Identifier?

Session Identifier is used to identify session. It has SessionId property. When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session or not. If not, a Session ID (120 - bit string) is generated by the web server and sent along with the response.
What are the advantages and disadvantages of using Outproc Session State?

The advantages of using session state are:

• It ensures data durability, since session state retains data even if ASP.NET work process restarts.
• It works in multi-process configuration, thus ensures platform scalability.

The disadvantages of using session state are:

• Since data in session state is stored in server memory, it is not advisable to use session state when working with large amount of data.
• Session state variable stays in memory until you destroy it, so too many variables in the memory that effects on the performance of the session state.
How do you provide secured communication in ASP.NET?

ASP.NET provides secured communication using Secure Sockets Layer. To use this SSL application we need to have an encryption key called a server certificate configured in IIS.

When a user requests a secured page, the server generates an encryption key for the user’s session. The encrypted response is then sent along with encryption key generated. In the client side, the response is then decrypted using same encryption key.
How do we implement ASP.NET Globalization?

• Create a resource file and compile them into a binary resource file.
• Create satellite assembly for each of the resource file for each culture.
• Store them in separate folder for easy access and replacement.
• Read the resources from the satellite assembly that is stored in different folders based on the location and culture.
Explain how to configure Trace switches in the application's .config file? Give the code snippet of config file.

Switches are configured using .config file. Trace switches can be configured and the trace output can be enabled or disabled in an application with the help of .config file. Configuring involves changing the value of the switch from an external source after being initialized. The values of the switch objects can be changed using the .config file.

TraceSwitch offers five levels of tracing from 0 to 4 i.e. it expose the following properties.

• TraceOff
• TraceError
• TraceWarning
• TraceInfo
• TraceVerbose

This class provides support for multiple levels instead of the simple on/off control offered by the BooleanSwitch class.

• Off - 0 Outputs no messages to Trace Listeners.
• Error - 1 Outputs only error messages to Trace Listeners.
• Warning - 2 Outputs error and warning messages to Trace Listeners.
• Info - 3 Outputs informational, warning and error messages to Trace Listeners.
• Verbose - 4 Outputs all messages to Trace Listeners.

Code Snippet of config file:
<configuration>

<system.diagnostics>
<switches>
<add name=”LevelSwitch” value=”3” />
</switches>
</system.diagnostics>
</configuration>


To construct a TraceSwitch:
TraceSwitch tSwitch=new TraceSwitch (“LevelSwitch”, “Trace Levels”);

System.Diagnostics.Trace.WriteIf (tSwitch.TraceInfo, “The Switch is 3 or more!”);


Here the TraceSwitch class returns true if the switch is at the same level or at the higher level than the property’s value. Here the TraceInfo property will return true if the switch value is set to 3 or more than 3.
What are the different ways to handle exceptions in ASP.NET? Explain them briefly?

There are three different ways to handle exceptions in ASP.NET. These are

a) Try/catch/finally block: You can enclose your codes in Try/Catch/Finally block. You can catch all exceptions in the catch block. The third part of this block is finally. It is executed irrespective of the fact that an exception has been raised.

b) Using Events like Page_Error and Application_Error:
• Page_Error: This is page event and is raised when any unhandled exception occur in the page.
• Application_Error: This is application event and is raised for all unhandled exceptions in the ASP.NET application and is implemented in global.asax

c) Using Custom error page: The <customErrors> section in web.config has two attributes that affect what error page is shown: defaultRedirect and mode. The defaultRedirect attribute is optional. If provided, it specifies the URL of the custom error page and indicates that the custom error page is shown instead of the Runtime Error. The mode attribute is required and accepts three values: On, Off, and RemoteOnly. These values have the following behavior:
On - indicates that the custom error page or the Runtime Error is shown to all visitors, regardless of whether they are local or remote.
Off - specifies that the Exception Detail is displayed to all visitors, regardless of whether they are local or remote.
RemoteOnly - indicates that the custom error page or the Runtime Error that is shown to remote visitors, while the Exception Detail is shown to local visitors.
Explain the points that differentiate between login controls and Forms authentication?

• Forms authentication can be easily implemented using login controls without writing any code.
• Login controls can perform different functions like prompting for user credentials, validating them and issuing authentication just as the Forms Authentication class.
• The Forms Authentication class is used in the background for the authentication ticket and ASP.NET membership is used to validate the user credentials.
• Login controls provides form authentication. If we implement authentication through Forms Authentication then we do it through code. On the other hand, login controls allows the easy implementation on the basis of Forms Authentication without writing any code. The class used for login controls are also Forms Authentication class. So instead of creating your own set of user credential validations and issuing of authentication ticket, it is simpler to use a normal login control.
What is DataSet and DataView?

DataSet- is an object used to store the data retrieved from the database. It can contain one or more tables .Each table in the dataset is known as Datatable. The constraints supported by the datatable are

1)UniqueConstraint.
2)ForeignKeyConstraint.

DataView - is used for the customized view of data of datatable, with the help of dataview we can filtered, searched or sort the data.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories