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

What will happen when you access the Global.asax file from a browser?

You can’t access the Global.asax file from a browser due to some security reasons.
The user gets an error message as "This type of page is not served" ,If the user requests the Global.asax file from your Web site.
How is the ASP.NET worker process impersonated ?

You have to set the identity element’s impersonation attribute in the application’s Web.config file, to use impersonation to run the ASP.NET worker process as a user other than ASPNET.
It is not a good idea to add ASPNET user to the Administrators group, why?

Your Web application will get full privileges on the server by adding the ASPNET user to the Administrators group.
It also poses a potential security risk because outside users might be able to manipulate your application to hack your server.
How do you copy the COM component to the server and register ?

Inorder to install or remove the COM components from the system,these COM components will provide a setup program.
If the component doesn’t provide a setup program, you can copy it to the server and register it using the MFC RegSvr32.exe utility, as shown below:

RegSvr32 MyComname.dll

What is difference between Web site and Web application ?

Hi,

Scenarios in which Web application projects :

0.we want to create web application the folder structure like One Project file and as well as Reference folder and along with One assembly file ie located in Bin folder.
1.We want to the compiler to create a single assembly for the entire site.
2.we want to be able to use the Edit and Continue feature of the Visual Studio debugger.
3. we want to run unit tests on code that is in the class files that are associated with ASP.NET pages.
4.we want to create project dependencies between multiple Web projects.
5.we want user MS-Build or Team Build for Compilation
6.we want avoid putting source code on a production server.
7.we want to use the automated deployment tools that are available in Visual Studio 2010.

Scenarios in which Web Sites :

0.we want to create website structure like folders and not having Reference folder
ask File Location
1.We want to include both C# and Visual Basic code in a single Web project
2.we want to open the production site in Visual Studio and update it in real time by using FTP.
3.If you pre compile the site, you want to be able to update individual ASP.NET Web pages (aspx files) without having to recompile the entire Web site.
4.if we want to create website ask File Location as FTP,HTTP etc
5.we want to be able to update individual files in production by just copying new versions to the production server, or by editing the files directly on the production server.


Regards,
Karunakar
What are anonymous types?

Annymous types are Data types that are Declared by the compiler, rather than trough the explicit class definition.

var n = { number = 10, message = "hi"};

Console.WriteLine(n.number + n.message);

Is there any difference between String and string ?

There is no special difference between both of them.
Actually System.String is a type which is specified by the Microsoft.Net runtime.
And string is a c# keyword for the same purpose.
Also int in C# ia same as the Integer in VB.NET.Both of them serve as System.Int32 for CLR.
How to display a number as a percent in .NET ?

A number with any type i.e., it might be int or double or decimal, it may be displayed as a percent(%) during the output.
It can be displayed likewise as setting the format type value in the ToString() method as shown in the below example.
Example:

decimal dec = 123.554466;
string s = dec.ToString("P2");


Output:

123.55%
Why String is a reference type ?

A String variable holds a reference to the object which contains each char in the string as the string types implement IEnumerable Interface. So, the strings are reference types.
In ToString("F2"), What does F2 mean ?

The output number string would be displayed upto some fixed point places after the decimal dot which is due to the instruction given by the letter F to the compiler.
The number 2 after the letter F is to display the output with 2 decimal places after the decimal dot, and the number has to be rounded.

Example:

double d = 35.3920002;
string s = d.ToString("F2");

Output:

35.39
Explain about carriage return ?

Carriage return is used to reset a device's position to the beginning of a line or text.
It is often called as CR or return.
In .NET, /r escape sequence is used to set this carriage return.
How can XSS attacks be prevented in ASP.NET 4.0 ?

Using HTML encoded code expressions, the XSS attacks can be prevented in ASP.NET 4.0.
The native <%= expression %> can be written as <%: expression %>
Explain the features of ASP.NET 4.0 ?

The advanced features of ASP.NET 4.0 are mentioned below:

1) Extensible Output cache
2) Compression of Session state
3) Individual control View state mode
4) Yhe properties such as Page.MetaKeyword and Page.MetaDescription
5) The method Response.RedirectPermanent
6) Routing in ASP.NET
7) Increase the URL character length
8) Html Encode New syntax
9) Predictable Client IDs
10) Refactoring of Web.config file
11) Auto-Start ASP.NET applications
12) Improvements on Microsoft Ajax Library
Explain about Response.RedirectPermanent() method in ASP.NET 4.0 ?

The Response.RedirectPermanent() method in ASP.NET 4.0 is used when an application is moved permenantly.
Below is an example which explains this method clearly.

Example:

RedirectPermanent("/newpath/foroldcontent.aspx");


The advantage of this method is that, the search engines will remove old page from its cache/database and will take this permanent redirection (Status 301). And also includes new page for better performance on search.
Explain about Extensible output caching in ASP.NET 4.0 ?

The Extensible Output Caching is used to store the HTTP response and page output in memory. With the help of this Output Caching Feature, ASP.NET can serve the subsequent requests more quickly by retrieving the data from memory.
The default configuration settings are shown below:


<caching>
<outputCache defaultProvider="AspNetInternalProvider">
<providers>
<add name="DiskCache"
type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/>
</providers>
</outputCache>
</caching>

In what way do you expand the size of allowable URL size in ASP.NET 4.0 ?

Below is the code snippet showing the expanding of allowable URL size in ASP.NET 4.0.

Code:

<httpRuntime maxRequestPathLength="260" maxQueryStringLength="2048" />


You have to modify the maxRequestPathLength inorder to allow the longer or shorter paths, i.e., where the URL does not includes the protocol, servername, and the querystring.
Inorder to allow longer or shorter querystrings, you have to modify the value of the maxQueryStringLength attribute.
Explain about shrinking session state in ASP.NET 4.0 ?

For storing data, ASP.NET provides 2 options namely,
1) Out of process session state
2) MS SQL server session state

Session-state providers stores the data out side the web application worker process in both the cases. Session state has to be serialized before it sends it to the external storage.
In ASP.NET 4.0, a new compression option is introduced for both out-of-process session state providers. We can set the compressionEnabled="true" in configuration file. ASP.NET will compress the session state by using the .NET Framework System.IO.Compression.GZipStream class.

Example:

<sessionState
mode="SqlServer"
sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"
allowCustomSqlDatabase="true"
compressionEnabled="true"
/>

Explain about refactoring of web.config in ASP.NET 4.0 ?

The major configuration elements in ASP.NET 4.0 are moved to the machine.config file. Now, the applications are inheritting these settings.
The advantage of this setting is that, the web.config file in ASP.NET 4 applications to be empty or to specify only which version of the framework the application is targeting.
This can be seen clearly in the below example.

Example:

< ? xml version="1.0" ? >
< configuration >
< system.web >
< compilation targetFramework="4.0" / >
< / system.web >
< / configuration >

Setting Meta tag through page directive in ASP.NET 4.0...

Met tags are used to give the basic information about a web page like page title, page description, page keywords and more.
These Meta tags can be set directly through page directive as shown in the below code snippet.


<%@ Page Title="Your Page Title" MetaDescription="Your Page Description" MetaKeywords="Your Page Keywords" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

What is Forms Authentication Ticket?

When a user is authenticated, then the cookie which is nothing but a Forms Authentication Ticket is stored on user's computer.
This will helps the user to automatically login, when the user re-visits the website.
The Forms authentication ticket information is sent to the web server along with the HTTP Request when it is created by revisiting the website by the user.
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