title: asp.net mvc and check for if a user is logged in
body: <p>I'm new in asp.net mvc and i need to check if a user is logged in or not in my application so i place the following piece of code in my global.asax</p>
  
  <pre><code>    void Application_PreRequestHandlerExecute(object sender, EventArgs e)
      {
          HttpApplication application = (HttpApplication)sender;
          HttpContext context = application.Context;
  
          string filePath= context.Request.FilePath;
          string fileExtention = VirtualPathUtility.GetExtension(filePath);
  
          // to skip request for static content like (.css or .js)
          if (fileExtention == "")
          {                
              if (filePath.ToLower() != "/account/login")
              {
                  var user = (Utilisateur)context.Session["USER"];
                  if (user == null)
                      context.Response.Redirect(@"~/account/login");
              }                
          } 
      }
  </code></pre>
  
  <p>I intercept each incoming request to do the checking I'd like to know if there are other ways to do this kind of work
  and thanks in advance.</p>