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

Which of these objects can be used to implement Page output Caching?

NOTE: This is objective type question, Please click question title for correct answer.
How can you create a Cookie that never expires?

It can be created using this coding.


HttpCookie h=new HttpCookie("userinfo");
h.Value="welcome";
//this line is very important
h.Expires=DateTime.MaxValue;
Response.Cookies.Add(h);


//Write this code in a suitable event handler
//eg: Button1_Click
How can you display server-side Time and Client Side Time in asp.net?

Server Side Time:

Write this code:
private void Page_Load(object sender, EventArgs e)
{
Response.Write(DateTime.Now.ToLongTimeString());
}


Client Side Time

<script type="text/javascript">
function abc()
{
var a=new Date();
document.write(a.getHours()+":"+a.getMinutes()+":"+a.getSeconds());
}
abc();

</script>
What is SSL?

SSL:

Secure Sockets Layer:

It ia secure way of sending data over the internet. It uses the https protocol and the
appropriate security certificates(encryption keys).
When a user requests a page using SSL, the web server generates an encryption key
for the user and then encrypts the page data.the encrypted page is then sent to the
browser. When the browser receives the SSL Page,it uses the same encryption key to
decrypt the received page.
What is process recycling?

It is the technique using which the asp.net worker process (aspnet_wp.exe) can be shut down or restarted for the purpose of repairing/maintaining the web sites. we can do this by using the appropriate attributes in the <processModel> tag of the machine.config file.
What are Web Parts?

Web Parts are the controls that can be closed, minimized,edited and moved by
the users.
WebPartManager is the main component of web parts. It defines the modes through
which we can control the operations of different web parts controls
They are used in blogs, news,stock exchange quotes etc.
To use Web Parts on a web page:
1)add a webpartmanager control on the top of the page.
2)Then add WebPartZone containers to the page.
3)Put the user interface controls to the WebPartZone containers.
In which of these modes, you can do dragging, dropping of the web parts

NOTE: This is objective type question, Please click question title for correct answer.
What is the default authentication mode of an ASP.NET wEB SITE?

NOTE: This is objective type question, Please click question title for correct answer.
What is Post- Cache Substitution?

It is a feature of the ASP.NET Framework that allows us to cache asp.net page partially.
example:
We may need dynamic output on one part of the page, but the other part of the page should remain static.

1)AdRotator: it is not cached even if the page is cached.

2)SubStitution control: we can use this control to display dynamic output even if the other part of the page is cached.
What is scavenging?

Scavenging is the process of deleting items from the cache when memory becomes low.
The criteria of removing the cached elements is either their inactivity for some time
or their low priority.
CacheItemPriority enumeration is used to determine the priority of cached items for scavenging.
What is difference between response.redirect and server.transfer ?

This is one of the favorite questions in ASP.NET Interviews. Every interviewer would like to know from the .NET candidate two things, how they differ technically and which scenarios should we use them.

Technical difference :- In Response.Redirect the following steps happen :-

1 - Client browser sends a signal to the server that he wants to go to xyz.aspx.
2 - Server responds back to the browser about the location of xyz.aspx and tells the client to go to that location.
3- Client gets the response and redirects to xyz.aspx.

In server.transfer the the following step happens :-

1 - Client browser sends a signal to the server that he wants to go to xyz.aspx.
2 - Server redirects to xyz.aspx and send the output to the client.

In other words in response.redirect there is a round trip while in server.transfer there are no round trips.

The next question what interviewer will ask is so does that mean we should always use server.trasfer and response.redirect is never needed.

Both of the are useful under different scenarios. Response.redirect is good when we want to go cross domains , in other words you want to redirect from www.questpond.com to www.microsoft.com. Server.trasfer do not work when you go cross domains.

Regards,
22 top important .NET interview questions
http://www.questpond.com/dotnet/Top-Dot-Net-Interview-Questions-and-Answers-Part1.html
How can you prevent the page from scrolllng up and down when some postback occurs ?

In the Page directive add this attribute MaintainScrollPositionOnPostback=true
Differences of ASP and ASP.NET Session State

ASP:

1)ASP 's Session State was stored in the same process that hosts ASP.

2)for different web servers, each Web server had its own session state.

There was a problem in sharing session states in a web farm situation.

3)No support for Cookieless sessions.

4)No web.config files for configuring the session state.

ASP.NET:

1)ASP.NET 's Session State is stored in the same process that hosts ASP.net(default)
It can also be stored out of process in an sql server database or a state server

2)different web servers can easily share the session state using the appropriate

configurations.

3)Supports Cookieless sessions.(<sessionState cookieless=true/>) in web.config file.

SessionId is visible in the browser.

4)uses web.config files for configuring the seesion state.
.Net and ASP.NET Interview Questions- Why can't we instantiate an abstract class?

.Net and ASP.NET Interview Questions- Why can't we instantiate an abstract class?

Answers:-
This is a nice .NET interview question. Abstract class is a half defined class and there is no point in creating a object of half a defined class. So you need to define a full implementation by creating a child class and you can then create the object of the child class.

My 50 .NET interview question http://www.questpond.com
What is the use of ValidateRequest attribute in the Page directive?

It is used to reduce the risk of cross-site scripting attacks for pages in ASP.NET applications. error messages like "Potentially dangerous value' are generated
because of this attribute.

example: in a textbox, if we write <script></script>
and then try to retreive its value, this attribute will result in an error.

It is true by default and can also be set to false.
Difference between Master Page and UserControl

Master Page and User Control are both used to provide a common design which can then be used in .aspx pages. We can pass data from Master Page or UserControl to .aspx pages and viceversa.

MasterPages and UserControl both cannot be accessed directly.


Master pages

1)Files with .Master extension. Introduced in ASP.NET 2.0.

code file: .master.cs or .master.vb extension

can use all toolbox controls.

2)These have a control known as the ContentPlaceHolder which reserves a storage location in which we can place the contents of a .aspx page.
The common part for the .aspx pages will be outside the ContentPlaceHolder

2 ContentPlaceHolders are by default , but we can increase or decrease the ContentPlaceholders as per our needs.

A referencing control of ContentPlaceHolder known as Content will be placed in .aspx page that uses the Master Page.

3)MasterPageFile attribute is added in the Page directive of the .aspx page when a Master Page is referenced in .aspx page. The .aspx page that uses the Master page i known as Content Page.

4)Can be referenced using Web.Config file also or dynamically by writing code in PreInit event.

5)More suitable for large designs(ex: defining the complete layout of .aspx page)

User Control

1)Files with .ascx extension.

Code file: .ascx.cs or .ascx.vb

can use all toolbox controls.


2)These do not have any ContentPlaceHolder control which makes it somewhat difficult in providing proper layout and alignment for large designs.

3)Register Tag is added when we drag and drop a user control onto the .aspx page.

4)Can be attached dynamically using LoadControl method.PreInit event is not mandatory in their case for dynamic attachment.

5)Suitable for small designs(Ex:1) logout button on every .aspx page.

2)this type of design:
enter shipper name : TextBox

shipper address: TextBox

Note:

UserControls can be used in Master Pages, but Master Pages cannot be used in User Controls.
Differences of Application and Session objects.

Application and Session objects are used for temporary data storage.
They store their data in the RAM of the web server.

Differences:

APPLICATION OBJECT:

1)It is returned through the Application property of the HttpContext class.

Its class is HttpApplicationState.

Namespace: System.Web

format of data storage:

ex: Application["hits"]=1;

"hits": key

1: value


2)Stores the data till the web application is shut down or we manually release its data using null/nothing or the Clear method is called.

3)It is created as soon as the web application is launched on the server.

4)Typical uses:

MORE USEFUL FOR STATIC DATA

a)Calculate the hits of a particular page of a web site.

b)Calculate the time taken for the execution of a web page.

c)Storing data of a readonly table/documentation file and displaying it across different pages.

5)It has no ID.


SESSION OBJECT:

1)It is returned through the Session property of the HttpContext class.

Its class is HttpSessionState.

Namespace: System.Web.SessionState.

format of data storage:

ex: Session["uname"]="ddd";

"uname": key

"ddd": value

2)Stores the data as specified by the Timeout property. Default Timeout is 20 minutes.

Timeout can be increased/decreased.
We can release data using null or Clear() method

Session can be killed using Session.Abandon() method.

Application object has no Abandon() method.

3)It is created when:

a)a unique instance of the browser is launched.

b)if the current instance of the browser is open and Timeout occurs/ Abandon() method is called.

c)if Session_End() event handler fires.

4)Typical uses:

USED FOR STORING DATA FOR SHORT DURATION:

Example:

a)MailBox: enter username on Login Page. The name is displayed in the mailbox page
when the mailbox page is opened from Login Page

b)Fetch data from database and display it on different pages.

c)Counters:

count the clicks of a button

we do not use Session object to calculate the number of Page hits since the Session data is reset everytime unique instance of the browser opens.

d)Shopping carts: display the data of a GridView in other page

e)Internet Usage: Calculate the internet Bill and the MB's used

5)Session object also has a SessionID.

---------------------------------------------------------------

Note:

1)Global.asax file is used for the initialization of the Application and Session objects that can then be used on different web pages of a web site.

2)Appication object is heavier as compared to Session object.So, we do not use

Application object for tasks like enter username on one page and displaying it

on another.

3)Session object stores the data on per user basis, while the Application object's
data is shared among the different users.
Differences between Application and Cache objects.

Application and Cache objects are used for storing static data for a certain period of time.Both use key-value pair format for data storage.
Both Application and Cache objects are one per web application.Their data can be accessed in all the pages of a web site.

The points of differences are:

APPLICATION OBJECT:

1)Application object always stores data on the server side RAM
example: Application["hits"]=1;
(key-value pair).

2)Application object maintains its data till the web application is shut down or we release the data manually by assigning null or Clear() method is called.

3)Application object has no Timeouts or File Dependencies.

4)Its data can be assigned using Global.asax file

5)Application object is not used for performance optimization.

USED in maintaining hit counters, data from readonly files/tables which can then
be displayed on varrious web pages.

CACHE OBJECT:

1)Cache object can store the data on server side RAM as well as client side RAM

example: -- Cache["data"]="asp.net";

2)Cache object maintains the static data as specified by the Absolute Expiration/ Sliding Expiration or File Dependency. The Time Period for Cache can be defined
using the Cache.Insert() overloaded method or Cache.Add() method.
It can be from seconds to years.

3)Cache object can be assigned data from web page and not from Global.asax file.

4)Cache is used for performance optimization. We retreive the Cache data from

the Cache without repeating the full cycle again, which is not so in the case

of the Application object.

USES OF CACHE OBJECT:

1)Static images for a certain period of time

2)Calculating the time of the users who login in a certain period of time.

3)On line exams: store the questions in the Cache and then retreive them from Cache.
What are QueryStrings? List some of the Advantages and Disadvantages ?

QueryString is additional information appended at the end of the URL

example:
http://www.dotnetfunda.com/post/PostExamQuestion.aspx?CSGAgreed=true

Querystring starts with ? sign

In this example: CSGAgreed: is the key of querystring
true: value of querystring
Querystring is used to transfer information from one page to another through the URL or it can be even on the same page

How we create
example:

Response.Redirect("Default2.aspx?name="+TextBox1.Text);


Advantages:
a. Supported by all the browsers
b. can be useful for executing database queries without needing textboxes
and button for entring the input and submitting
c. Easy to use.

Disadvantages:
a. All the information in querystring is visible to user not secure.
b. limited to URL length of 255 characters.
What is a Global Theme?

A Global Theme is available to all the Web Sites on your Web Server.

For a File System based web site, follow these steps to create and implement a Global Theme

1)Create a Folder in this path

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\themes

example: create a SkinFile Folder below the themes folder.


2)Create a .skin file in the SkinFile folder.
save the file.


3)specify one skin in the .skin file
example:
<asp:TextBox runat="server" BackColor="LightBlue"/>

4)To attach the SkinFile Folder with a File System based web site:

a)Open a File System based web site:

b)Paste a web server control TextBox on the .aspx page

c)In the Page Directive, add this attribute :

Theme="SkinFile"

5)Run the .aspx page. The BackColor of TextBox will be LightBlue.
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