Question: Why a conventional ASP web page is considered to be stateless amd how do
u overcome this using ASP.NET?
Answer: Whenver a URL request is made, Web server creates instance of requested
web form, generates HTML and posts it to browser for rendering. It then
destroys instance of web form on the server. When user submits data back to
the web server, a new instance of web form is created which has no
knowledge of earlier webform. Hence conventional web page is stateless. In
ASP.NET before web form get destroyed the state of the webform is stored in
Viewstate(hidden control) on the page and when the page is posted back, the
state of the webform is restored from view state.
Question: What is a web-farm and how do u manage session in web-farm?
Answer: A web-farm is group of webservers hosting a single web application.
Sice the web application is shared across multiple servers, session info can
not be stored in process memory of any of servers. It should be stored in a
centralizes database or state machine.
Question: How do you preserve persistent data, such as simple variables, in a Web
Answer: You can preserve data in state variables, such as ApplicationState,
SessionState, or ViewState.
Question: How cookieless session works in ASP.NET?
Answer: In cookieless session session id gets embedded in URL automatically. So
when url request is made, session id is stripped from URL by ASP.NET
And is used to identify session information belonging to user.
Question: Does cookieless session works when absolute paths are specified ?
Answer: No cookieless session does not work with absolute paths. It works only with
Question: Is it possible to protect view state from tampering when it's passed over an
Answer: Yes. Simply include an @ Page directive with an
EnableViewStateMac="true" attribute in each ASPX file you wish to
protect, or include the following statement in Web.config: his
configuration directive appends a hash (officially called the message
authentication code, or MAC) to view state values round-tripped to
the client and enables ASP.NET to detect altered view state. If
ASP.NET determines that view state has been altered when a page
posts back to the server, it throws an exception.
The hash is generated by appending a secret key (the
validationKey value attached to the
Machine.config) to the view state and hashing the result. An
attacker can't modify view state and fix up the hash without
knowing the secret key, too.
Question: How do u synchronize access to Application variables by multiple threads.
Answer: Use Application.Lock and Application.Unlock before accessing Application
Question: How do u cache a web page in ASP.NET?
Answer: <%@ outputcache duration=”60” varybyparam=”none”>
Question: What is difference between following statements
1 - <%@ outputcache duration=”60” varybyparam=”none”>
2 - <%@ outputcache duration=”60” varybyparam=”*”>
3 - <%@ outputcache duration=”60” varybyparam=”name”>
Answer: Statement 1 caches only one version of the page irrespective of querystring
parameters. Statement 2 caches multiple versions of same page I any of
quewrystring parameter varies. Statement 3 caches multiple versions of the
page for different values of parameter xyz.
Question: What is difference between canche.insert and cache.add method
Answer: The Add and Insert methods have the same signature, but there are subtle
differences between them. First, calling the Add method returns an object
that represents the cached item, while calling Insert does not. Second, their
behavior is different if you call these methods and add an item to the cache
Question: What is cache dependency and how do u add it?
Answer: If object1 has Cache dependency on object2 , then whnever object2 changes,
object1 is removed from the cache.
e.g. following example sets up a database connection string denedency on
Cache.Insert("MyData1", connectionString, new
Question: What are 2 expiration policies for Cached objects?
Answer: 1. Absolute expiration: This is fixed duration expiration. For cache
duration of 10 seconds, object is removed from cache after 10 seconds
no matter what.
2. Sliding expiration: Canche duration varies based on frequency of
access. E.g. If there is sliding expiration of 10 seconds and item is
accessed from the cached again at 8th second, then object is reached
again for the next 10 seconds
Question: What is fragment caching?
Answer: Fragment caching is caching enabled for ascx controls.
Question: How do u notify an application when an item is removed from the cache?
Answer: By implementing event CacheItemRemovedCallBack.
Question: What is the main difference between the Button server control and the Button HTML
Answer: When clicked, the Button server control triggers an ASP.NET Click event procedure
on the server. The Button HTML control triggers the event procedure indicated in
the button' s onclick attribute, which runs on the client.
Question: List two different exception-handling approaches in ASP.NET Web applications.
Answer: Exceptions can be handled in exception-handling blocks using the Try, Catch, and
Finally keywords in Visual Basic .NET or the try, catch, and finally keywords in
Visual C#. They can also be handled using Error event procedures at the Global,
Application, or Page levels using the Server object' s GetLastError and ClearError
Question: Write the HTML for a hyperlink that will send mail when the user clicks the link.
Answer: Send mail
Question: Show the code that writes a cookie containing the user name “Rob Young” and the
current date to the user' s computer. Set the cookie to remain on the user' s computer
for 30 days.
Answer: HttpCookie cookUserInfo = new HttpCookie("UserInfo")
CookUserInfo["Name"] = "Rob Young"
CookUserInfo["Time"] = DateTime.Now.ToString()
cookUserInfo.Expires = DateTime.Now.AddDays(30)
Question: What is the difference between the CurrentCulture property and the Current-
Answer: The CurrentCulture property affects how the .NET Framework handles dates,
currencies, sorting, and formatting issues. The Current UICulture property
determines which satellite assembly is used when loading resources.
Question: How do you detect the user' s culture?
Answer: Use the Request object' s UserLanguages array. The value at element 0 corresponds
Compiled by email@example.com Page 7 of 20
to one of the culture codes used by the CultureInfo class. For example:
SLang = Request.UserLanguages(0)
Question: What are 2 layout options for a webform
Answer: Grid layout: This is the default. Controls are placed exactly where you draw them
and they have absolute positions on the page. Use grid layout for Windows-style
applications, in which controls are not mixed with large amounts of text.
Flow layout: This places controls relative to other elements on the page. If you add
elements at run time, the controls that occur after the new element move down. Use
flow layout for document-style applications, in which text and controls are
Question: Can an ASPX file contain more than one form marked runat="server"?
Question: How do I comment out statements in ASPX files?