Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
void Application_BeginRequest(object sender, EventArgs e)
       {
           // Code that runs on application startup
           // Check whether to begin the request

       }
       void Application_AuthenticateRequest(object sender, EventArgs e)
       {

           /*This is called just before authentication is performed.
            * You could add your own authentication logic in this method to provide custom authentication*/

       }
       void Application_AuthorizeRequest(object sender, EventArgs e)
       {
           /*This is called when the authentication stage is completed.
            * It's executed at the stage to determine user privileges and permissions.
            * You could add custom code to assign user special privileges.*/

       }
       void Application_ResolveRequestCache(object sender, EventArgs e)
       {
           // Code that runs on application startup

       }
       void Application_AcquireRequestState(object sender, EventArgs e)
       {
           /*This is called just before session-specific data is retrieved for the client
            * and is used to populate Session Collection.*/
       }
       void Application_PreRequestHandlerExecute(object sender, EventArgs e)
       {
           // Code that runs on application startup

       }


       //Handler Now Execute the request



       void Application_PostRequestHandlerExecute(object sender, EventArgs e)
       {


       }
       void Application_ReleaseRequestState(object sender, EventArgs e)
       {
           /* This method is called when the session-specific information is about to be serialized
            * from the Session Collection so that it's available for the next request. */

       }
       void Application_UpdateRequestCache(object sender, EventArgs e)
       {
           //This is called just before information is added to the output cache.
           //If you have enabled output caching for your web page,
           //it's now the time ASP.NET insert the rendered HTML into the cache.


       }
Posted
Updated 12-Oct-11 1:05am
v2

I think the supplied comments pretty much are the examples - but as a futher hint how about

C#
void Application_Start(object sender, EventArgs e)
{
  // Check database server is up and running
}

void Application_End(object sender, EventArgs e)
{
  // check all file shares etc are closed
}
 
Share this answer
 
I want Examples for events those called for Every request..

but not regular events like Application_start,Application_End,Application_Disposed
 
Share this answer
 
cs file code validateadmin from database through validateadmin() method first
C#
void validateuser(string id, string pass)
   {

       string ob = Request.QueryString["returnurl"];
       if (validateadmin())
       {
           if (ob == null)
           {

               FormsAuthentication.Initialize();
               string strrole = null;
               strrole = "admin";
               FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, userid.Text, DateTime.Now, DateTime.Now.AddMinutes(30), false, strrole, FormsAuthentication.FormsCookiePath);
               Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)));
               //loggedmein();
               Response.Redirect("~/Admin/adminMain.aspx");
           }
           else
           {
               FormsAuthentication.RedirectFromLoginPage(userid.Text, false);
           }
       }
       else
       {
           lblmsg.Visible = true;
           lblmsg.Text = "wrong user id or password";
       }


   }



then

in global.asax

C#
protected void Application_AuthenticateRequest(object sender, EventArgs e)
  {
      if (this.Context.Request.IsAuthenticated)
      {
          string str = null;
          if ((HttpContext.Current.User.Identity.Name.ToLower() == "admin"))
          {
              str = "admin";
          }

          else
          {
              str = "usr";
          }
          string[] roles = new string[2];
          roles[0] = str;
          Context.User = new System.Security.Principal.GenericPrincipal(this.Context.User.Identity, roles);
      }
  }


in webconfig

HTML
<appsettings>
    <add key="ConnectionString" value="con" />
    <add key="strrole" value="usr" />
</appsettings>
<system.web>
<customerrors mode="Off" />
    <compilation debug="true" targetframework="4.0" />
<authentication mode="Forms">
  <forms loginUrl="login.aspx" name="FlashUpload" path="/"></forms>
</authentication>
</system.web>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900