ASP.NET Questionnaire
Number:
1
Heading:
State / Session management
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.
Comments: Level:
SE
Number:
2
Heading:
State / Session management
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.
Comments: Level:
SSE
Number:
3
Heading:
State / Session management
Question:
How do you preserve persistent data, such as simple variables, in a Web application?
Answer:
You can preserve data in state variables, such as ApplicationState, SessionState, or ViewState.
Comments: Level:
SE
Number:
4
Heading:
State / Session management
Compiled by
[email protected]
Page 1 of 20
ASP.NET Questionnaire 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.
Comments: Level:
TL
Number:
5
Heading:
State / Session management
Question:
Does cookieless session works when absolute paths are specified ?
Answer:
No cookieless session does not work with absolute paths. It works only with relative path.
Comments: Level:
TL
Number:
6
Heading:
State / Session management
Question:
Is it possible to protect view state from tampering when it's passed over an unencrypted channel?
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 <machineKey> element in 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.
Comments: Level:
TL
Compiled by
[email protected]
Page 2 of 20
ASP.NET Questionnaire Number:
7
Heading:
State / Session management
Question:
How do u synchronize access to Application variables by multiple threads.
Answer:
Use Application.Lock and Application.Unlock before accessing Application Variables.
Comments: Level:
SE
Number:
8
Heading:
State / Session management
Question:
How do u cache a web page in ASP.NET?
Answer:
<%@ outputcache duration=”60” varybyparam=”none”>
Comments: Level:
SE
Number:
9
Heading:
State / Session management
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.
Comments:
Related to 8
Level:
SE
Number:
10
Heading:
State / Session management
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
Compiled by
[email protected]
Page 3 of 20
ASP.NET Questionnaire that is already stored there. The Insert method replaces the item, while the Add method fails. Comments: Level:
SSE
Number:
11
Heading:
State / Session management
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 xml file. Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Comments: Level:
SE
Number:
12
Heading:
State / Session management
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
Comments: Level:
SE
Number:
13
Heading:
State / Session management
Question:
What is fragment caching?
Answer:
Fragment caching is caching enabled for ascx controls.
Comments: Compiled by
[email protected]
Page 4 of 20
ASP.NET Questionnaire Level:
SSE
Number:
14
Heading:
State / Session management
Question:
How do u notify an application when an item is removed from the cache?
Answer:
By implementing event CacheItemRemovedCallBack.
Comments: Level:
SSE
Number:
15
Heading:
ASP.NET Web-forms Life Cycle
Question:
What is the main difference between the Button server control and the Button HTML control?
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.
Comments: Level:
SE
Number:
16
Heading:
ASP.NET Web-forms Life Cycle
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 methods.
Comments: Level:
SSE
Number:
17
Heading:
ASP.NET Web-forms Life Cycle
Compiled by
[email protected]
Page 5 of 20
ASP.NET Questionnaire Question:
Write the HTML for a hyperlink that will send mail when the user clicks the link.
Answer:
Send mail
Comments: Level:
SE
Number:
18
Heading:
ASP.NET Web-forms Life Cycle
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) Response.Cookies.Add(cookUserInfo)
Comments:
Code shown is written in C#
Level:
SE
Number:
19
Heading:
ASP.NET Web-forms Life Cycle
Question:
What is the difference between the CurrentCulture property and the CurrentUICulture property?
Answer:
The CurrentCulture property affects how the .NET Framework handles dates, currencies, sorting, and formatting issues. The CurrentUICulture property determines which satellite assembly is used when loading resources.
Comments: Level:
SSE
Number:
20
Heading:
ASP.NET Web-forms Life Cycle
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 protected]
Page 6 of 20
ASP.NET Questionnaire to one of the culture codes used by the CultureInfo class. For example: SLang = Request.UserLanguages(0)
Comments: Level:
SE
Number:
21
Heading:
ASP.NET Web-forms Life Cycle
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 intermingled.
Comments: Level:
SE
Number:
22
Heading:
ASP.NET Web-forms Life Cycle
Question:
Can an ASPX file contain more than one form marked runat="server"?
Answer:
No
Comments: Level:
SE
Number:
23
Heading:
ASP.NET Web-forms Life Cycle
Question:
How do I comment out statements in ASPX files?
Answer:
<%-
--%>
Comments: Level:
SE
Compiled by [email protected]
Page 7 of 20
ASP.NET Questionnaire
Number:
24
Heading:
UI Controls / Data bound controls
Question: Answer:
How do you get several RadioButton controls to interoperate on a Web form so that only one of the RadioButtons can be selected at once? Set the GroupName property of each RadioButton to the same name.
Comments: Level:
SE
Number:
25
Heading:
UI Controls / Data bound controls
Question:
What is wrong with the following line of code? Server.Transfer("Default.htm");
Answer:
You can' t use the Transfer method with HTML pages. It works only with .aspx pages.
Comments: Level:
SE
Number:
26
Heading:
UI Controls / Data bound controls
Question:
How do you display a page in one frame from a hyperlink in another frame?
Answer:
Use the element' s target attribute to specify the frame to display the page. For example, the following hyperlink displays a page in the main frame of a frameset: Show the answers!
Comments: Level:
SE
Number:
27
Heading:
UI Controls / Data bound controls
Question:
Briefly describe the best uses for each of the three types of Web controls
Answer:
Create a user control when you want to…
Compiled by [email protected]
Page 8 of 20
ASP.NET Questionnaire …quickly create a group of controls that can be reused throughout a project to perform some logical unit of work. Create a composite custom control when you want to… …combine one or more existing controls into a compiled assembly that can be easily reused in many different projects. Create a rendered control when you want to… …build an entirely new control that can be compiled into an assembly for use in multiple projects.
Comments: Level:
SSE
Number:
28
Heading:
UI Controls / Data bound controls
Question: Answer:
What is the most important method to override when creating a composite custom control? You override the CreateChildControls method to add existing controls to a composite custom control.
Comments: Level:
SE
Number:
29
Heading:
UI Controls / Data bound controls
Question:
What is the most important method to override when creating a rendered control?
Answer:
You override the Render method when creating a rendered custom control.
Comments: Level:
SE
Number:
30
Heading:
UI Controls / Data bound controls
Question:
What is the advantage of using CSS rather than in-line styles for formatting a Web application?
Compiled by [email protected]
Page 9 of 20
ASP.NET Questionnaire Answer:
Using CSS allows you to maintain formatting separately from the content of your Web forms, so changes are easier to make and consistency is easier to maintain.
Comments: Level:
SSE
Number:
31
Heading:
UI Controls / Data bound controls
Question:
How will u get or set the values from a CheckBoxList or RadioButtonList control?
Answer:
, use a For Each loop to check each control in the list private void Button1_Click(object sender, System.EventArgs e) { foreach (ListItem lstItem in RadioButtonList1.Items) { if (lstItem.Selected) Response.Write(lstItem.Text + " is selected.
"); } }
Comments:
Code shown is in C#
Level:
SE
Number:
32
Heading:
UI Controls / Data bound controls
Question:
Specify form tag which contains file upload control.
Answer: