Wednesday 3 March 2010

FAQ's - ASP.NET

Life cycle of ASP.NET 2.0 Page ?
Life cycle of the page is defined as the list of events that get fired from the Page initialization to page rendering. The list of events is illustrated along with the descriptions.
Name of the Event - When does the event fire
PreInit - Occurs at the beginning of page initialization.
Init - Occurs when the server control is initialized, which is the first step in its lifecycle.
InitComplete - Occurs when page initialization is complete.
PreLoad - Occurs before the page Load event.
Load - Occurs when the server control is loaded into the Page object.
PreRender - Occurs after the Control object is loaded, but prior to rendering.
PreRenderComplete - Occurs before the page content is rendered.
SaveStateComplete - Occurs after the page has completed saving all view state and control state information for the page and controls on the page.
LoadComplete - Occurs at the end of the load stage of the page's life cycle.
Unload - Occurs when the server control is unloaded from memory.

What is the Pre-Compilation feature of ASP.NET 2.0? How does the new folder structure help for the same?
By default, ASP.NET Web pages and code files are compiled dynamically when users first request a resource such as a page from the Web site. After pages and code files have been compiled the first time, the compiled resources are cached, so that subsequent requests to the same page are extremely efficient. This was in previous versions of ASP.NET, but in ASP.NET 2.0 we have a feature called as pre-compilation. With this, ASP.NET can also pre-compile an entire site before it is made available to users. We have some pre-defined folder structures for enabling this feature of pre-compilation. Let us list down some of the folders with a brief description of what they are meant for.
• App_Code – meant for storing classes
• App_Themes – meant for storing CSS files, Images, etc.
• App_Data –meant for storing XML files, Text Files, etc.
• App_GlobalResources – meant for storing all the resources at global level E.g. resx files, etc
• App_LocalResources – meant for storing all the resources at local/Page level

What is the class name for accessing the Configuration in .NET 2.0?
The class name used for accessing configuration in .NET 2.0 is ConfigurationManager. The ConfigurationManager class is a static class which has all the methods for accessing application configuration file
. For web applications we have WebConfigurationManager class. The WebConfigurationManager allows us to access machine and application information.

What is Authentication in ASP.NET?
Authentication is the process of identifying a user with identification credentials like User name and Password with some authority. Generally after authentication the system gets to know who the user is. ASP.Net has some authentication providers. Let us discuss some of them.
Windows Authentication Provider - Windows authentication in conjunction with Microsoft Internet Information Services (IIS) authentication to secure ASP.NET applications
Forms Authentication Provider – An application-specific login form and performs authentication using user code.
Passport Authentication provider – Centralized authentication service provided by Microsoft offers a single login and core profile service for member sites.

What is Authorization in ASP.NET?
Authorization determines whether an identity/user should be granted access to a specific resource. Authorization requires that the authentication is already done. There are 2 ways to authorize access to a given resource:
• File authorization - File authorization is performed by the FileAuthorizationModule. It checks the access control list (ACL) of the .aspx or .asmx handler file to determine whether a user should have access to the file.
• URL authorization - URL authorization is performed by the UrlAuthorizationModule, which maps users and roles to URLs in ASP.NET applications.
Ex:

<[allow|deny] users roles verbs />


What is the difference between Response.Redirect() and Server.Transfer()?
Redirect Method:
- Client knows about the redirection of the URL.
- ASP.net can force reauthorization by using the Redirect method instead of the Transfer method.
- Response.Redirect is little bit slower, but it retains the new URL.
- Cannot use HTTPContext.Items.

Transfer Method:
- Client does not know anything about the transfer. It appears to be the same old URL for the client.
- ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. You need to have a Custom logic for the same.
- Server Transfer is faster as it reduces 1 less trip to the client.
- HTTPContext.Items are accessible.

No comments:

Post a Comment