Ans.Response.Output.Write() allows you to write formatted output.
2.What is the difference between Server.Transfer and Response.Redirect?
Ans.Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client’s browser.This provides a faster response with a little less overhead on the server.Server.Transfer does not update clients url historylist or current url.
Response.Redirect is used to redirect the user’s browser to another page or site.This performs a trip back to the client where client’s browser is redirected to the new page.The user’s browser history list is updated to reflect the new address.
3.Explain the difference between server-side code and client-side code.
Ans.Server-side code executes on the server.Client-side code executes on the client’s browser.
4.Describe the difference between inline code and code behind.
Ans.Inline code written along side the html in a page.Code-behind is code written in seprate file and refrenced by .aspx in page.
5.What methods are fired during page load?
Ans. Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.
6.What data types do the RangeValidator control supports?
Ans. Integer,String and Date.
7.What is ViewState?
Ans. ViewState is the mechanism by which page state (information) is maintained between page post backs, i.e. a web form is submitted by the user, this same page performs some processing and perhaps presents further information to the user.ViewState allows the state of objects(serializable) to be stored in a hidden field on the page.
8.Can any object be stored in a ViewState?
Ans. An object that either is serializable or has a TypeConverter defined for it can be persisted in ViewState.
9. What should you do to store an object in a Viewstate?
Ans. Do serialization of convert the object to string
10.Explain how Viewstate is being formed and how it’s stored on client.
Ans.The type of ViewState is System.Web.UI.StateBag, which is a dictionary that stores name/value pairs. ViewState is persisted to a string variable by the ASP.NET page framework and sent to the client and back as a hidden variable. Upon postback, the page framework parses the input string from the hidden variable and populates the ViewState property of each control. If a control uses ViewState for property data instead of a private field, that property automatically will be persisted across round trips to the client. (If a property is not persisted in ViewState, it is good practice to return its default value on postback.)
11. Where is ViewState information stored ?
Ans. ViewState information is stored in hidden fields.
12. What are benefits and Limitation of using Hidden fields ?
Ans. The benefits of using hidden fields to store client-side state include:
• No server resources are required. The hidden field is stored and read directly from the page.
• Almost all browsers and client devices support forms with hidden fields.
• Hidden fields are simple to implement.
• Hidden fields are good for caching data in Web farm configurations because the data is cached on the client.
The limitations of using hidden fields are:
• The hidden field can be tampered with. The information in this field can be seen if the page output source is viewed directly, creating a potential security issue.
• The hidden field does not support rich structures; it offers only a single value field in which to place information. To store multiple values, you must implement delimited strings and write the code required to parse those strings.
• Page performance decreases when you store large values because hidden fields are stored in the page.
13.How can you use Hidden frames to cache client data ?
Ans. You can use hidden frames to cache data on the client, avoiding the roundtrips to the server that are inherent in hidden field and view state implementations. You create a hidden frame in your page that loads a Web page into the frame containing your data. The pages in your application can access this data using client-side scripting. This implementation does not require any server resources because the data fields in the hidden frame are stored and read directly from the page.
14.What are benefits and Limitation of using Hidden frames?
Ans. The benefits of using hidden frames to store client-side state include:
• The ability to cache more than one data field.
• The avoidance of roundtrips of data during postbacks.
• The ability to cache and access data items stored in different hidden forms.
• The ability to access JScript® variable values stored in different frames if they come from the same site.
The limitations of using hidden frames are:
• Functionality of hidden frames is not supported by all browsers. Do not rely on hidden frames to provide data for the essential functionality of your pages.
• The hidden frame can be tampered with, and the information in the page can be seen if the page output source is viewed directly, creating a potential security threat.
• There is no limit to the number of frames (embedded or not) that you can hide. In frames that bring data from the database and that contain several Java applets or images, a large number of frames can negatively affect performance of the first page load.
15.What is Global.asax used for?
Ans.The Global.asax is used to implement application and session level events.
16. What are major events in GLOBAL.ASAX file ?
Ans. The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following events:
• Application_Init: Fired when an application initializes or is first called. It’s invoked for all HttpApplication object instances.
• Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
• Application_Error: Fired when an unhandled exception is encountered within the application.
• Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
• Application_End: Fired when the last instance of an HttpApplication class is destroyed. It’s fired only once during an application’s lifetime.
• Application_BeginRequest: Fired when an application request is received. It’s the first event fired for a request, which is often a page request (URL) that a user enters.
• Application_EndRequest: The last event fired for an application request.
• Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework begins executing an event handler like a page or Web service.
• Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is finished executing an event handler.
• Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
• Application_PreSendContent: Fired before the ASP.NET page framework sends content to a requesting client (browser).
• Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
• Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
• Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
• Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
• Application_AuthenticateRequest: Fired when the security module has established the current user’s identity as valid. At this point, the user’s credentials have been validated.
• Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.
• Session_Start: Fired when a new user visits the application Web site.
• Session_End: Fired when a user’s session times out, ends, or they leave the application Web site.
17.How do you validate the controls in ASP.NET page?
Ans. Using the validation controls that are meant for this.
18. Which control is used to make sure the values in two different controls are matched?
Ans. CompareValidator control.
19.Name two properties common in every validation control.
Ans.ControlToValidate property and Text property.
20. Can the validation be done in the server side? Or this can be done only in the Client side?
Ans. Client side is done by default. Server side validation is also possible. We can switch off the client side and server side can be done.
21. How to manage pagination in a page?
Ans. Using pagination option in DataGrid control. We have to set the number of records for a page, then it takes care of pagination by itself.
22. Which are various modes of storing ASP.NET session?
Ans. ASP.Net Session State supports three modes. inproc, sqlserver, and stateserver.
• InProc - session kept as live objects in web server (aspnet_wp.exe). Use “cookieless” configuration in web.config to “munge” the sessionId onto the URL (solves cookie/domain/path RFC problems too!)
• StateServer - session serialized and stored in memory in a separate process (aspnet_state.exe). State Server can run on another machine
• SQLServer - session serialized and stored in SQL server
23. Is Session_End event supported in all session modes ?
Ans. Session_End event only supported in inproc mode when the session data is stored in the asp.net worker process.
24. What are the precautions you will take in order that StateServer Mode work properly ?
Ans. Following are the things to remember so that StateServer Mode works properly :-
• StateServer mode session data is stored in a different process so you must
ensure that your objects are serializable.
• elements in Web.config should be indentical across all
servers.So this ensures that encryption format is same across all computers.
• IIS metabase (\LM\W3SVC\2) must be identical across all servers in that
25. What are the precautions you will take in order that SQLSERVERMode work properly ?
Ans.Following are the things to remember so that SQLSERVER Mode works properly.
• SQLSERVER mode session data is stored in a different process so you must ensure that your objects are serializable.
• IIS metabase (\LM\W3SVC\2) must be indentical across all servers in that farm.
• By default Session objects are stored in “Tempdb” , you can configure it store outside “TempDB” by running microsoft provided SQL script.
Note :- “TempDB” database is re-created after SQL SERVER computer reboot.If you want to maintain session state with every reboot best is to run SQL Script and store session objects outside “TempDB” database.
26. Where do you specify session state mode in ASP.NET ?
sqlConnectionString=”data source=192.168.1.1; Integrated
Above is sample session state mode specified for SQL SERVER.
27. What are the other ways you can maintain state ?
Ans.Other than session variables you can use the following technique to store state :
• Hidden fields
• View state
• Hidden frames
• Query strings
28. What are benefits and Limitation of using Cookies?
Ans.Following are benefits of using cookies for state management :-
• No server resources are required as they are stored in client.
• They are light weight and simple to use
Following are limitation of using cookies :-
• Most browsers place a 4096-byte limit on the size of a cookie,although support
for 8192-byte cookies is becoming more common in the new browser and
client-device versions available today.
• Some users disable their browser or client device’s ability to receive cookies,
• Cookies can be tampered and thus creating a security hole.
• Cookies can expire thus leading to inconsistency.
Below is sample code of implementing cookies
Request.Cookies.Add(New HttpCookie(“name”, “user1”))
29. What is Query String and What are benefits and Limitation of using Query Strings?
Ans.A query string is information sent to the server appended to the end of a page URL.
Following are the benefits of using query string for state management:-
• No server resources are required. The query string is contained in the HTTP request for a specific URL.
• All browsers support query strings.
Following are limitations of query string :-
• Query string data is directly visible to user thus leading to security problems.-
• Most browsers and client devices impose a 255-character limit on URL length.
Below is a sample “Login” query string passed in URL http://www.querystring.com/
login.asp?login=testing.This querystring data can then be requested later by using
30. What is application object ?
Ans.Application object can used in situation where we want data to be shared across users globally.
31.What’s the difference between Cache object and application object?
Ans.The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
32.How can get access to cache object ?
Ans.The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.
33.What are dependencies in cache and types of dependencies ?
Ans.When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update.Following are the supported dependency.
• File dependency :- Allows you to invalidate a specific cache item when a disk based file or files change.
• Time-based expiration :- Allows you to invalidate a specific cache item depending on predefined time.
• Key dependency :-Allows you to invalidate a specific cache item depending when another cached item changes.
34.Can you show a simple code showing file dependency in cache ?
Ans.Partial Class Default_aspx
Public Sub displayAnnouncement()
Dim announcement As String
If Cache(“announcement”) Is Nothing Then
Dim file As New _
announcement = file.ReadToEnd
Dim depends As New _
Cache.Insert(“announcement”, announcement, depends)
Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
Note :- Above source code can be obtained from CD in “CacheSample”
folder.”Announcement.txt” is in the same folder which you can play around to see the results.
Above given method displayAnnouncement() displays banner text from Announcement.txt file which is lying in application path of the web directory.Above method first checks is the Cache object nothing , if the cache object is nothing then it moves further to load the cache data from the file.Whenever the file data changes the cache object is removed and set to nothing.
35.What is Cache Callback in Cache ?
Ans.Cache object is dependent on its dependencies example file based , time based etc.Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.
36. What is scavenging ?
Ans.When server running your ASP.NET application runs low on memory resources , items are removed from cache depending on cache item priority.cache item priority is set when you add item to cache.BY setting the cache item priority controls which items scavenging is removed first.
37. What are different types of caching using cache object of ASP.NET?
Ans.You can use two types of output caching to cache information that is to be transmitted to and displayed in a Web browser:
• Page Output Caching
Page output caching adds the response of page to cache object.Later when page is requested page is displayed from cache rather than creating the page object and displaying it.Page output caching is good if the site is fairly static.
• Page Fragment Caching
If parts of the page are changing, you can wrap the static sections as user controls and cache the user controls using pagefragment caching.
38. How can you cache different version of same page using ASP.NET
cache object ?
Ans.Output cache functionality is achieved by using “OutputCache” attribute on ASP.NET page header.Below is the syntax
• VaryByParam :- Caches different version depending on input parameters send through HTTP POST/GET.
• VaryByHeader:- Caches different version depending on the contents of the page header.
• VaryByCustom:-Lets you customize the way the cache handles page variations by declaring the attribute and overriding the GetVaryByCustomString handler.
• VaryByControl:-Caches different versions of a user control based on the value of properties of ASP objects in the control.
39. How will implement Page Fragment Caching ?
Ans.Page fragment caching involves the caching of a fragment of the page, rather than the entire page. When portions of the page need to be dynamically created for each user request this is best method as compared to page caching.You can wrap Web Forms user control and cache the control so that these portions of the page don’t need to be recreated
40. What’s the sequence in which ASP.NET events are processed?
1. Initialize: Initialize settings needed during the lifetime of the incoming Web request.
2. Load view state: At the end of this phase, the ViewState property of a control is automatically populated
3. Process postback data: Process incoming form data and update properties accordingly.
4. Load: Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data.
5. Send postback change notifications: Raise change events in response to state changes between the current and previous postbacks.
6. Handle postback events: Handle the client-side event that caused the postback and raise appropriate events on the server.
7. Prerender: Perform any updates before the output is rendered. Any changes made to the state of the control in the prerender phase can be saved, while changes made in the rendering phase are lost.
8. Save state: The ViewState property of a control is automatically persisted to a string object after this stage. This string object is sent to the client and back as a hidden variable. For improving efficiency, a control can override the SaveViewState method to modify the ViewState property.
9. Render: Generate output to be rendered to the client.
10. Dispose: Perform any final cleanup before the control is torn down. References to expensive resources such as database connections must be released in this phase.
11. Unload: Perform any final cleanup before the control is torn down. Control authors generally perform cleanup in Dispose and do not handle this event.
Initialization, Page Load, PreRendor, Page unload
41. What is event bubbling ?
Ans. Event Bubbling is nothing but events raised by child controls is handled by the parent control. Example: Suppose consider datagrid as parent control in which there are several child controls.There can be a column of link buttons right.Each link button has click event.Instead of writing event routine for each link button write one routine for parent which will handlde the click events of the child link button events.Parent can know which child actaully triggered the event.That thru arguments passed to event routine.
42. How do we assign page specific attributes ?
Ans. @Page directive defines page-specific attributes used in ASP.NET pages(.aspx). @Page directives allow you to set attributes that directly affect your ASP.NET pages that end with the .aspx extension. The following is a small example of what an @Page directive looks like:<%@ page language=”c#” buffer=”true” Explicit=”true” runat=”server” %>
43. What’s the use of @ Register directives ?
Ans. @ Register Creates an association between a tag prefix and a custom control, which provides developers with a concise way to refer to custom controls in an ASP.NET application file (including Web pages, user controls, and master pages).
44. What’s the use of SmartNavigation property ?
Ans. A SmartNavigation is a property of the Page class in System.Web.UI. When a request comes in to Internet Explorer 5.5 or higher and SmartNavigation is turned on (set to true), the following actions are performed: The flash caused by navigation is eliminated The scroll position is persisted when moving from page to page Element focus is persisted between navigations Only the last page state in the browser’s history is retained However, according to the Microsoft® .NET Framework Class Library documentation, smart navigation is best used only with ASP.NET pages that require frequent postbacks but have visual content that does not change dramatically on return.In most circumstances, you should not set this property in code. Set the SmartNavigation attribute to true in the @ Page directive in the .aspx file. When the page is requested, the dynamically generated class sets this property for you. Smart navigation is a feature that you must test in your particular scenarios to be sure the proper behavior is exhibited.
45. What is AppSetting Section in “Web.Config” file ?
46What’s the use of @ OutputCache directive in ASP.NET?
Ans.@ OutputCacheDeclaratively controls the output caching policies of an ASP.NET page or a user control contained in a page.
47.How can we create custom controls in ASP.NET?
Ans. custom controls can be created in either of the following 3 methods.
1. Creating as a composite control : This method uses and combines the existing controls to give a custom functionality which can be used across different projects by adding to the control library. This can provide for event bubbling from child controls to the Parent container, custom event handling and properties. The CreateChildControls function of the Control class should be overridden for creating this custom control. This can also support design time rendering of the control.
2. Deriving from an existing control : This method of creating a custom control derives from an existing ASP .Net control and customizing the properties that we need. This also can support custom event handling, properties etc.,
3. Creating a control from Scratch : This method is the one which needs maximum programming. This method needs even the HTML code for the custom controls to be written by the programmer. This may also need one to implement the IPostBackDataHandler and IPostBackEventHandler interfaces. A detailed explanation with example for this is available at Rendering Custom Controls Sample in MSDN.
48. How many types of validation controls are provided by ASP.NET ?
Ans.RequiredField Validator Control,Range Validator Control, RegularExpression Validator Control,Custom Validator Control and Validation Summary Control are provided by ASP.NET.
49. Can you explain what is “AutoPostBack” feature in ASP.NET ?
Ans. AutoPostBack is built into the form-based server controls, and when enabled, automatically posts the page back to the server whenever the value of the control in question is changed.
50. How can you enable automatic paging in DataGrid ?
Ans. Using the Built-In Paging Controls
To use default paging, you set properties to enable paging, set the page size, and specify the style of the paging controls. Paging controls are LinkButton controls. You can choose from these types: Next and previous buttons. The button captions can be any text you want. Page numbers, which allow users to jump to a specific page. You can specify how many numbers are displayed; if there are more pages, an ellipsis ( … ) is displayed next to the numbers. You must also create an event-handling method that responds when users click a navigation control.
To use the built-in paging controlsSet the control’s AllowPaging property to true. Set the PageSize property to the number of items to display per page.
To set the appearance of the paging buttons, include a
51. What’s the difference between “Web.config” and “Machine.Config” ?
Ans. machine.config is where u define all the machine specific settings.. common for all the web application..
web.config is where u define all the setings for that perticular web application.. it override the machine.config settings for application.
52. What’s the difference between login controls and Forms authentication?
Ans.Login controls are an easy way to implement Forms authentication without having to write any code. For example, the Login control performs the same functions you would normally perform when using the FormsAuthentication class—prompt for user credentials, validate them, and issue the authentication ticket—but with all the functionality wrapped in a control that you can just drag from the Toolbox in Visual Studio. Under the covers, the login control uses the FormsAuthentication class (for example, to issue the authentication ticket) and ASP.NET membership (to validate the user credentials). Naturally, you can still use Forms authentication yourself, and applications you have that currently use it will continue to run.
53. What’s difference between Authentication and authorization?
Ans. Authentication is the process of identifying and verifying who the client accessing the server is.
For example, if you use
* Windows authentication and are browsing an ASP.NET page from server — ASP.NET/IIS would automatically use NTLM to authenticate you as SYNCFUSION\user1 (for example).
* Forms based authentication, then you would use an html based forms page to enter username/password — which would then check a database and authenticate you against the username/password in the database.
Authorization is the process of determining whether an authenticated user has access to run a particular page within an ASP.NET web application. Specifically, as an application author decide to grant or deny the authenticated user “SYNCFUSION\user1″ access to the admin.aspx page. This could be done either by explictly granting/denying rights based on the username — or use role based mappings to map authenticated users into roles.
54. What are the various ways of authentication techniques in ASP.NET?
Ans. ASP.NET provides three ways to authenticate a user:
* Windows authentication,
* Forms authentication, and
* Passport authentication
55. What’s difference between Datagrid , Datalist and repeater ?
Ans. Datagrid is most restrictive as regards to customization followed by DataList and finally Repeater is the most customizable.Datagrid has built in paging, sorting and editing capabilities which are not there with the other two controls. So if you want users to sort / page / edit data, datagrid is the natural choice.DataList and repeater have better performance than datagrid. So if performance is a major concern, for example, a site with large number of concurrent visitors, then you could think of datalist or repeater.Repeater is the most customizable. It allows you to create structures like nested lists, for example.A datagrid row displays one record from the data source, while a datalist row can display more than one records (set by RepeatColumns property)Datagrid and Datalist are derived from WebControl while Repeater is not, and so does not have the stylistic properties of web controls.All are similar in that they have a datasource property and ItemCreated, ItemDataBound and ItemCommand events.
56. What is Tracing in ASP.NET ?
Ans. ASP.NET introduces new functionality that allows you to write debug statements, directly in your code, without having to remove them from your application when it is deployed to production servers. Called tracing, this feature allows you to write variables or structures in a page, assert whether a condition is met, or simply trace through the execution path of your page or application.
57. How do we enable tracing ?
Ans.Instead of enabling tracing for individual pages, you can enable it for your entire application. In that case, every page in your application displays trace information. Application tracing is useful when you are developing an application because you can easily enable it and disable it without editing individual pages. When your application is complete, you can turn off tracing for all pages at once.When you enable tracing for an application, ASP.NET collects trace information for each request to the application, up to the maximum number of requests you specify. The default number of requests is 10. You can view trace information with the trace viewer.By default, when the trace viewer reaches its request limit, the application stops storing trace requests. However, you can configure application-level tracing to always store the most recent tracing data, discarding the oldest data when the maximum number of requests is reached.
To Enable Tracing for an application
1.Open your Web site’s Web.config file. If no Web.config file exists, create a new file in the root folder and copy the following into it:
2.Add a trace element as a child of the system.web element.
3.In the trace element, set the enabled attribute to true.
4.If you want trace information to appear at the end of the page that it is associated with, set the trace element’s pageOutput attribute to true. If you want tracing information to be displayed only in the trace viewer, set the pageOutput attribute to false.For example, the following application trace configuration collects trace information for up to 40 requests and allows browsers on computers other than the server of origin to display the trace viewer. Trace information is not displayed in individual pages.
58. What exactly happens when ASPX page is requested from Browser?
Ans. At its core, the ASP.NET execution engine compiles the page into a class, which derives from the code behind class (which in turn derives directly or indirectly from the Page class). Then it injects the newly created class into the execution environment, instantiates it, and executes it. ASP.NET, on the other hand, can accept code in any language that is compatible with the .NET framework, because it’s compiled down natively just like other code.
59.How can we kill a user session ?
Ans.The Abandon method destroys all the objects stored in a Session object and releases their resources.
If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.Syntax: Session.Abandon.
60.How do I send email message from ASP.NET?
Ans. The .NET Framework supplies a SMTP class that enables you to send a simple e-mail message. If you have to send an e-mail with added functionalities, you have to make use of the MailMessage class. With the help of this class, you can insert attachments, set priorities, and much more, very easily. You can also send HTML e-mail using this class.61. What are different IIS isolation levels?Ans. There are 3 IIS isolation levels.
* Low (IIS Process): ASP pages run in INetInfo.Exe, the main IIS process, therefore they are executed in-process. This is the fastest setting, and is the default under IIS4. The problem is that if ASP crashes, IIS crashes as well and must be restarted (IIS5 has a reliable restart feature that automatically restarts a server when a fatal error occurs).
* Medium (Pooled): In this case ASP runs in a different process, which makes this setting more reliable: if ASP crashes IIS won’t. All the ASP applications at the Medium isolation level share the same process, so you can have a web site running with just two processes (IIS and ASP process). IIS5 is the first Internet Information Server version that supports this setting, which is also the default setting when you create an IIS5 application. Note that an ASP application that runs at this level is run under COM+, so it’s hosted in DLLHOST.EXE (and you can see this executable in the Task Manager).
* High (Isolated): Each ASP application runs out-process in its own process space, therefore if an ASP application crashes, neither IIS nor any other ASP application will be affected. The downside is that you consume more memory and resources if the server hosts many ASP applications. Both IIS4 and IIS5 supports this setting: under IIS4 this process runs inside MTS.EXE, while under IIS5 it runs inside DLLHOST.EXE.
62.How do you deploy an ASP.NET application?
Ans.You can deploy an ASP.NET Web application using any one of the following three deployment options.
2.Using the Copy Project option in VS .NET
3.Deployment using VS.NET installer