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

Describe about HttpContext Class ?

HttpContext class:


• The HttpContext class encapsulates HTTP-specific information about an HTTP request.

• This includes response/request headers, server variables, session variables, user information, and so on. Of particular interest is a property called Current, which returns an instance of the HttpContext class that represents the current HTTP request.

• Another important property in the HttpContext class is User, which contains security information about the user who made the Web request. The User property returns a type the implements the IPrincipal interface

Write the code which will create a cookie containing the user name DotnetFunda and the current date to the user computer. Set the cookie as that remains on the user computer for 10 days?

HttpCookie cookieWebInfo = new HttpCookie("WebInfo");

CookieWebInfo["Name"] = "DotnetFunda";
// here CookieWebInfo is an object of class HttpCookie
CookieWebInfo["Time"] = DateTime.Now.ToString();
cookieWebInfo.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(cookieWebInfo);


Here the HttpCookie class is under the System.Web namespace. Here 'Expires' sets the duration, when cookie expires.
Describe the difference between Web and Window applications?

Web Forms: These are used for server controls, HTML controls, user controls, or custom controls that is created especially for the Web forms. Web applications are displayed in a browser only. These are instantiated on the server; it sent to the browser and destroys immediately. These can run in any machine if that machine supports browser.

Windows Forms: Windows applications can run on the same machine as they are displayed only on that machine. It displays their own windows and has more control over how those windows are going to display. These are instantiated and it exists for as long as needed and is destroyed.
What are Button HTML control and the Button Server control? What is the main difference between them?

The Button HTML control is used to work as a control in forms, and it can also be used to performs actions anywhere on the form through scripts. It is used to display a button like push button. These buttons may be a submit button or a command button.

The Button control allows you to create a push button on the Web Forms page. Here you can dynamically add a Button web server control to a page by writing certain codes.

The Button HTML control triggers the event procedure defined in the button onclick event attribute, which runs at the client side. When clicked on the button, the Button server control triggers an ASP.NET Click event procedure on the server that is written on the asp.net code behind page.
What are the two different levels of variables that are supported by Asp.net?

There are two levels of variables supported in ASP.NET.

Page level variable: int, float, char, string and all other .net data type whose scope is limited to that particular page only.

Object level variable: Application Level, Session Level that is used to access the data throughout the application.
Explain what is the purpose of using EnableViewState property?

• When a page is postback, then it allows the page to save the users input on a form.
• It also saves all the server side values as a hidden value on the page before sending that page to the clients for a particular given control in the ViewState.
• When a page is posted back to the server, at the same time the server control is recreated within the state stored in ViewState.
What are Shallow Copy and Deep Copy in .NET?

The terms "Shallow Copy " and "Deep Copy " which refer to the way the objects are copied, for example, during the invocation of a copy constructor or assignment operator. The deep copy can also be called as member wise copy and the copy operation respects object semantics. For example, copying an object that has a member of type standard string ensures that the corresponding standard string in the target object is copy-constructed by the copy constructor of class string.

Shallow copy: This is nothing but creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a value type then a bit-by-bit copy of the field is performed. If it is a reference type then the reference is copied but not the referred object. Therefore, the original object and its clone refer to the same object.

Deep copy: Deep copy is partially same as shallow copy, but the difference is deep copy copies the whole object and makes a different object, it means it do not refer to the original object while in case of shallow copy the target object always refer to the original object and changes in target object also make changes in original object. It serializes the objects and deserializes the output.
What are the Difference between Compiler and Debugger?

Compiler is software or we can say it is a set of software that translates one computer Language to another computer language. Most of the cases the High level Programming Language are converting to low level Programming Language.

Most of the time the Programs analyze and examine error, so for that Debugger is used. Debugger is another program that is used for testing and debugging of other programs. It is also able to tell where the error occurred in your application.
What is Debugger and what are the types of Debugger?

Debugger is a program that is used for testing and debugging purpose for the programs. Mainly it is used to analyze and examine error conditions in the application. With the help of this we can able to find where the error occurred in your application.

There are two types of Debugger that is:

CorDBG (command-line debugger) - To use this CorDbg, you must compile the original C# file using the debug switch.

DbgCLR (graphic debugger) - The Visual Studio .NET uses this DbgCLR debugger.
What is the difference between Cookie and Session in Asp.Net?

• The basic and main difference between cookie and session is that cookies are stored in the user's browser but sessions can't store in user's browser. This specifies which is best used for.

• A cookie can keep all the information in the client's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie.

• Sessions are not reliant on the user allowing a cookie. They work like a token in the browser which allowing access and passing information while the user has opened his browser. The problem in sessions is when you close the browser the session will automatically lost. So, if you had a site requiring a login, this couldn't be saved as a session but it can be saved as a cookie, and the user has to re-login every time they visit.
Define and describe different File Name Extensions in Asp.net?

Applications written in Asp .net have different files with different extension. Native files generally have .aspx or .ascx extension. File name containing the business logic depend on the language that you are using. For Example c# files have extension aspx.cs.

.asax: Default.asax, used for application-level logic

.ascx: Web UserControls i.e. custom controls can be placed onto web pages.

.ashx: for custom HTTP handlers.

.asmx: web service pages that are Code behind page of an asmx file is placed into the app_code folder.

.axd: when enabled in web.config requesting trace.axd outputs application-level tracing. It is also used for special webresource.axd handler which allows control or component developers to package a component or control complete with images, script, css etc. for deployment in a single file.

.config: web.config is the only file in a Web application. This is the by default extension (machine.config similarly affects the entire Web server and all applications on it). Also ASP.NET facilitates to create and consume other config files. These are stored in XML format.

.cs/vb: Code files (cs indicates C#, vb indicates Visual Basic). Code behind files predominantly has the extension ".aspx.cs" or ".aspx.vb" for the two most common languages. Other code files can also exist in the web folders with the cs/vb extension. These are placed inside the App_Code folder where they are dynamically compiled and available to the whole application.

.dbml: LINQ to SQL data classes file

.master: Master page file

.resx: resource files for localization. Resource files can be global (e.g. messages) or "local" which means specific for a single aspx or ascx file.

.sitemap: sitemap configuration files. The default file name is web.sitemap.

.skin: theme skin files.

.svc: Windows Communication Foundation service file.
Describe the different properties of cookie in Asp.Net?

The different properties of a cookie are:

Domain: This property defines the domain of Web servers to which this cookie should be made available. When the Web server matches the defined domain then that web browser will send a cookie back to a Web server. It specifies the domain for which the cookie is valid. The domain associated with the cookie for example, aspx.superexpert.com

Expires: It specifies the expiration date for a persistent cookie. It sets the current state of the cookie. Also it gets and sets the expiration date and time for the cookies.

HasKeys: This is a Boolean value which indicates whether the cookie is a cookie dictionary or not.

Name: The name of the cookie.

Path: It defines a Web server path to which the cookie should be made available. The path associated with the Cookie that is it sets the URI's to which the cookie applies. The default value is /.

Secure: A value that indicates whether the cookie should be sent over an encrypted connection only. It sets the Secure attribute of any SESSIONID cookies associated with the web application. It allows values as:
true — Sets Secure to true.
false — Sets Secure to false.
dynamic — The SESSIONID cookie inherits the Secure setting of the request that initiated the session. The default value is False.

Value: The value of the Cookie that is it sets the value for the cookie.

Values: It is a NameValueCollection that represents all the key and value pairs stored in a Cookie dictionary.
What is Profile Based State in ASP State Management ?

A profile based state is nothing but the state changes is saved permanently for a particular profile. That means the state is saved manually by the user. If there was no saving done the Default settings will be applied .


For Example .
If we login into igoogle.com, there if we have our customized page set once, untill and unless we change it delibrately it will be the same page.
Explain the ways, so that you can modify the additional permissions required by an application?

There are 3 different ways to modify the additional permissions required by an application. That is

• Permit the ASP.NET user access to the required files. To access this option, the server must have Windows NT file system (NTFS).
• Change the group of ASP.NET user.
• Use impersonation to run the process as another user.
In which 3 levels we have a configuration file for an ASP.NET web application?

Web server level: At this level the Machine.config file is located in Windows\Microsoft.NET\Framework\version\config directory. This helps to set the base configuration for all .NET assemblies that is running on the server.

Application or Web site level: At this level the Web.config file located in the IIS root directory. It helps to set the base configuration for all Web applications and overrides the settings that are in Machine.config file.

In the sub directory of an application root folder: This override the settings in the root folders of web.config file.
Write the steps to host a web application on a web server?

Step-1: Use IIS to set up a virtual folder for a physical folder in an application.

Step-2: Copy all the web application to the virtual directory location.

Step-3: Then add a shared .NET component to the server’s global assembly cache (GAC).

Step-4: Set the security permission on the server that allows the application to access required resources.
Why it is required to monitor a deployed Web application?

When you have deployed a Web application, then you need to monitor that Web application because you have to know how it performs on the server. Many issues can crop up for your application at this point because of

• The number of users accessing that Web application.
• The changeable nature of user interaction.
• The possibility of malicious attack by the user.
Write three major steps which involves in maintaining a deployed web application?

There are three major steps involved in maintaining a deployed web application:

• Monitoring the application for clearing errors, performance, and security issues.
• Make change in the application as issues are arising.
• Setup the application to respond to user traffic.
How do you run the Event Viewer to view application, system, and security events as they happen?

For running of Event Viewer, let’s choose the Event Viewer from the Administrative Tools sub-menu of Windows Start menu. (You can get the Administrative Tools menu in Windows XP Professional by right click on Start button, then select Properties and click the customize button on the Start Menu tab. The Administrative Tools option will appear on the Advanced tab of the customize Start Menu dialog box). After that when you will click on the Event Viewer shortcut, and then the windows will display the Event Viewer snap-in in the MMC (Microsoft Management Console).
Mention the different levels of events for Event Viewer?

There are 3 different levels of events for Event Viewer

• Informational events.
• Warning events.
• Error events.
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