About Us
Quadtechindia is your ultimate guide to free and open source code for ASP.NET,C#,php,SQL Server, active server pages (ASP), javscript,database,PHP,source code for Software developers arround the world. It has an open forum for programmers to view codes post by other programmers and can also post their codes for their and others use as knowledge is the only wealth that increases on sharing it with others.
Recent Posts of Forum
Re: One Liners
[quote author=bhupen link=topic=475.msg556#msg556 date=1327298833]
Can we put multiple catch blocks in a single try statement ? ? ? ?
[/quote]
Yes
===================================================================
Re: One Liners
Can we put multiple catch blocks in a single try statement ? ? ? ?
By - BHUPEN===================================================================
Global.asax file
The Global.asax file, which is derived from theHttpApplication class, maintains a pool of HttpApplication objects,and assigns them to applications as needed. The Global.asax filecontains the following events:
Application_Init: Fired when an application initializes or is firstcalled. It's invoked for all HttpApplication object instances.
Application_Disposed: Fired just before an application isdestroyed. This is the ideal location for cleaning up previouslyused resources.
Application_Error: Fired when an unhandled exception is encounteredwithin the application.
Application_Start: Fired when the first instance of theHttpApplication class is created. It allows you to create objectsthat are accessible by all HttpApplication instances.
Application_End: Fired when the last instance of an HttpApplicationclass is destroyed. It's fired only once during an application'slifetime.
Application_BeginRequest: Fired when an application request isreceived. It's the first event fired for a request, which is oftena page request (URL) that a user enters.
Application_EndRequest: The last event fired for an applicationrequest.
Application_PreRequestHandlerExecute: Fired before the ASP.NET pageframework begins executing an event handler like a page or Webservice.
Application_PostRequestHandlerExecute: Fired when the ASP.NET pageframework is finished executing an event handler.
Applcation_PreSendRequestHeaders: Fired before the ASP.NET pageframework sends HTTP headers to a requesting client (browser).
Application_PreSendContent: Fired before the ASP.NET page frameworksends content to a requesting client (browser).
Application_AcquireRequestState: Fired when the ASP.NET pageframework gets the current state (Session state) related to thecurrent request.
Application_ReleaseRequestState: Fired when the ASP.NET pageframework completes execution of all event handlers. This resultsin all state modules to save their current state data.
Application_ResolveRequestCache: Fired when the ASP.NET pageframework completes an authorization request. It allows cachingmodules to serve the request from the cache, thus bypassing handlerexecution.
Application_UpdateRequestCache: Fired when the ASP.NET pageframework completes handler execution to allow caching modules tostore responses to be used to handle subsequent requests.
Application_AuthenticateRequest: Fired when the security module hasestablished the current user's identity as valid. At this point,the user's credentials have been validated.
Application_AuthorizeRequest: Fired when the security module hasverified that a user can access resources.
Session_Start: Fired when a new user visits the application Website.
Session_End: Fired when a user's session times out, ends, or theyleave the application Web site.
The event list may seem daunting, but it can beuseful in various circumstances.
A key issue with taking advantage of the eventsis knowing the order in which they're triggered. TheApplication_Init and Application_Start events are fired once whenthe application is first started. Likewise, theApplication_Disposed and Application_End are only fired once whenthe application terminates. In addition, the session-based events(Session_Start and Session_End) are only used when users enter andleave the site. The remaining events deal with applicationrequests, and they're triggered in the following order:
Application_BeginRequest
Application_AuthenticateRequest
Application_AuthorizeRequest
Application_ResolveRequestCache
Application_AcquireRequestState
Application_PreRequestHandlerExecute
Application_PreSendRequestHeaders
Application_PreSendRequestContent
Application_PostRequestHandlerExecute
Application_ReleaseRequestState
Application_UpdateRequestCache
Application_EndRequest
A common use of some of these events issecurity. The following C# example demonstrates various Global.asaxevents with the Application_Authenticate event used to facilitateforms-based authentication via a cookie. In addition, theApplication_Start event populates an application variable, whileSession_Start populates a session variable. The Application_Errorevent displays a simple message stating an error has occurred.
protected void Application_Start(Object sender,EventArgs e) {
Application["Title"] = "Builder.com Sample";
}
protected void Session_Start(Object sender, EventArgs e) {
Session["startValue"] = 0;
}
protected void Application_AuthenticateRequest(Object sender,EventArgs e) {
// Extract the forms authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if(null == authCookie) {
// There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try {
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
} catch(Exception ex) {
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket) {
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the UserData property wasassigned
// a pipe delimited string of role names.
string[2] roles
roles[0] = "One"
roles[1] = "Two"
// Create an Identity object
FormsIdentity id = new FormsIdentity( authTicket );
// This principal will flow throughout the request.
GenericPrincipal principal = new GenericPrincipal(id,roles);
// Attach the new principal object to the current HttpContextobject
Context.User = principal;
}
protected void Application_Error(Object sender, EventArgs e){
Response.Write("Error encountered.");
}
This example provides a peek at the usefulnessof the events contained in the Global.asax file; it's important torealize that these events are related to the entire application.Consequently, any methods placed in it are available through theapplication's code, hence the Global name.
Here's the VB.NET equivalent of the previouscode:
Sub Application_Start(ByVal sender As Object, ByVale As EventArgs)
Application("Title") = "Builder.com Sample"
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e AsEventArgs)
Session("startValue") = 0
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVale As
EventArgs)
' Extract the forms authentication cookie
Dim cookieName As String
cookieName = FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie
authCookie = Context.Request.Cookies(cookieName)
If (authCookie Is Nothing) Then
' There is no authentication cookie.
Return
End If
Dim authTicket As FormsAuthenticationTicket
authTicket = Nothing
Try
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
Catch ex As Exception
' Log exception details (omitted for simplicity)
Return
End Try
Dim roles(2) As String
roles(0) = "One"
roles(1) = "Two"
Dim id As FormsIdentity
id = New FormsIdentity(authTicket)
Dim principal As GenericPrincipal
principal = New GenericPrincipal(id, roles)
' Attach the new principal object to the current HttpContextobject
Context.User = principal
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e AsEventArgs)
Response.Write("Error encountered.")
End Sub
A good resource
The Global.asax file is the central point forASP.NET applications. It provides numerous events to handle variousapplication-wide tasks such as user authentication, applicationstart up, and dealing with user sessions. You should be familiarwith this optional file to build robust ASP.NET-applications
===================================================================
what is .NET Partial Classes?
One of the language enhancements in .NET 2.0—available in both VB.NET 2005 and C# 2.0—is support for partial classes. In a nutshell, partial classes mean that your class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. During compile time, it simply groups all the various partial classes and treats them as a single entity.
One of the greatest benefits of partial classes is that it allows a clean separation of business logic and the user interface (in particular the code that is generated by the visual designer). Using partial classes, the UI code can be hidden from the developer, who usually has no need to access it anyway. Partial classes will also make debugging easier, as the code is partitioned into separate files.Here are some good reasons to use partial classes:
1. They allow programmers on your team to work on different parts of a class without needing to share the same physical file. While this is useful for projects that involve big class files, be wary: If you find your class file getting too large, it may well signal a design fault and refactoring may be required.
2. The most compelling reason for using partial class is to separate your application business logic from the designer-generated code. For example, the code generated by Visual Studio 2005 for a Windows Form is kept separate from your business logic (we will discuss this in a later section). This will prevent developers from messing with the code that is used for the UI. At the same time, it will prevent you from losing your changes to the designer-generated code when you change the UI.
===================================================================
Globalization and Localization
Multilingual website can be created using Globalization and Localization.
Using Globalization we change the Currency, Date, Numbers, etc to Language Specific Format.
To change the string which is there in the label, button, etc to language specific string we use Localization.
In Localization we have to create different Resource files for different languages.
During this process we use some classes present in System.Resources, System.Globalization, System.Threading namespaces.
Note: There is no way we can localize dynamic text.
===================================================================
Diff between authentication and Authorization
Authentication is process of finding whether the user is valid.Example username and password u enter in mail page.That process is authentication Authorization is the process of holding rights for particular task.Example: Usually admin have right to install software in companies and others are not granted this right
By - VICTER===================================================================
How to handle exceptions without using try catch finally
It is possible using Application Blocks
It can be handled in Application_error event.
===================================================================
authentication Types
Windows authentication enables you to identify users without creating a custom page. Credentials are stored in the Web server’s local user database or an Active Directory domain. Once identified, you can use the user’s credentials to gain access to resources that are protected by Windows authorization.
Forms authentication enables you to identify users with a custom database, such as an ASP.NET membership database. Alternatively, you can implement your own custom database. Once authenticated, you can reference the roles the user is in to restrict access to portions of your Web site.
Passport authentication relies on a centralized service provided by Microsoft. Passport authentication identifies a user with using his or her e-mail address and a password, and a single Passport account can be used with many different Web sites. Passport authentication is primarily used for public Web sites with thousands of users.
Anonymous authentication does not require the user to provide credentials.
===================================================================
Length of query String
Query string length depends on browser compatability
Firefox --------> 4000 Characters
IE5.0,IE6.0,IE7.0----->2048 Characters(256bytes)
Opera --------> 4050 Characters
NetScape6 --------> 2000Characters
NetScape4 ---------> 30000 Characters-
===================================================================
Execution of an asp.net page
IIS recieves the request.
IIS examines the extension to know if this extention is registered with asp.net?(generally aspx, ashx, asmx)
IIS hands over asp.net requests to aspnet_isapi
Application Manager is created
HttpContext , HttpRequest, HttpResponse objects are created
Modules are in initialized (This is where modules register their own methods with HTTPApplication events)
HttpAppliction object created (in practical scenarios we have global.asax which always inherits from HttpApplication class. in those casesa an object of global.asax is created.)
various HTTPApplication events are executed (like begin_request, authenticate, authorize, resolve_cache, resolve_state, get_handler, execute_Hadler,update_cache, update_state, end_request) for the exact list of events please refer to MSDN.
execute_handler is the method which is responsible for page life cycle. We can also custome httphandlers which perform necessary action on server and writes the output in the HTTPResponse object.
the response goes through the remaining events of HttpApplication and can be tampered with using modules registered with those events.
finally, the httprespoonse is sent back.
===================================================================



