global-asax

how to stop application asp.net with global.asax


I want to stop my application asp.net Mvc in Session_Start after a test and show to user that he isn't authorized for this application

 protected void Session_Start(object sender, EventArgs e)
 {
     if (test)
     {
         //stop application
         // say to user : not authorized
     }
 }

Solution

  • Finally i send a response and close the session and it works

    protected void Session_Start(object sender, EventArgs e){
             if (test){
                  ASCIIEncoding encoding = new ASCIIEncoding();
                  string postData = "<h2 style=\"color:RED;\"Not authorized!!</h2>. ";
                  byte[] data = encoding.GetBytes(postData);
                  char[] buf = postData.ToCharArray();
                  HttpContext.Current.Response.Write(buf, 0, buf.Count());
                  HttpContext.Current.Response.Flush();
                  HttpContext.Current.ApplicationInstance.CompleteRequest();
                  Session.Abandon();
             }
         }