You are on page 1of 3

http://www.c-sharpcorner.

com/uploadfile/aa04e6/major-events-in-global-asax-file/

http://aspalliance.com/1114_Understanding_the_Globalasax_file.all

http://www.c-sharpcorner.com/blogs/globalasax-events1

exemplo completo global.asax/

http://www.aspdotnet-suresh.com/2011/05/what-is-use-of-globalasax-file-in.html

protected void Application_Start(object sender, EventArgs e)


{
// Code that runs on application startup
WriteFile("Application Starting");
}
protected void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
WriteFile("Application Ending");
}
protected void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
string strError;
strError = Server.GetLastError().ToString();
if(Context!=null)
{
Context.ClearError();
Response.Write("Application_Error" + "<br/>");
Response.Write("<b>Error Msg:</b>" + strError + "<br/>"+"<b>End Error Msg<b/>");
}
}
protected void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Response.Write("Session_Start" + "<br/>");
}

protected void Session_End(object sender, EventArgs e)


{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Response.Write("Session_End"+"<br/>");
}
protected void Application_BeginRequest(object sender,EventArgs e)
{
Response.Write("Application_BeginRequest" + "<br/>");
}
protected void Application_EndRequest(object sender, EventArgs e)
{
Response.Write("Application_EndRequest" + "<br/>");
}
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
Response.Write("Application_AcquireRequestState" + "<br/>");
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
Response.Write("Application_AuthenticateRequest" + "<br/>");
}
protected void Application_AuthorizeRequest(object sender, EventArgs e)
{
Response.Write("Application_AuthorizeRequest" + "<br/>");
}
protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
Response.Write("Application_PostRequestHandlerExecute" + "<br/>");
}
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
Response.Write("Application_PreRequestHandlerExecute" + "<br/>");
}
protected void Application_PreSendRequestContent(object sender, EventArgs e)
{
Response.Write("Application_PreSendRequestContent" + "<br/>");
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
Response.Write("Application_PreSendRequestHeaders" + "<br/>");
}
protected void Application_ReleaseRequestState(object sender, EventArgs e)
{
Response.Write("Application_ReleaseRequestState" + "<br/>");
}
protected void Application_ResolveRequestCache(object sender, EventArgs e)
{
Response.Write("Application_ResolveRequestCache" + "<br/>");
}
protected void Application_UpdateRequestCache(object sender, EventArgs e)
{
Response.Write("Application_UpdateRequestCache" + "<br/>");
}
protected void Application_Disposed(object sender, EventArgs e)
{
Response.Write("Application_Disposed"+"<br/>");
}
public void WriteFile(string strText)
{
StreamWriter strWriter = new StreamWriter(@"C:test.txt", true);
string str = DateTime.Now + " " + strText;
strWriter.WriteLine(str);
strWriter.Close();
}
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 was assigned
// 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 HttpContext object
Context.User = principal;
}
protected void Application_Error(Object sender, EventArgs e) {
Response.Write("Error encountered.");
}

You might also like