I want my MVC application to check (for each request) if the current user has a profile. If no profile is found, I want to redirect them to the Profile page to send them.
protected void Application_AuthenticateRequest()
{
if (HttpContext.Current.User != null)
{
if (!HttpContext.Current.User.HasProfile())
Response.RedirectToRoute("Profile");
}
}
I turned on IPrincipal to enable the "User.HasProfile ()" method to check if the user has a profile. It works, but the problem is that Application_AuthenticateRequest is called for every single request, including javascript, css, etc.
In addition, it creates a redirect loop when I try to execute Response.RedirectToRoute ("Profile").
The only way I found this is to add the following to my IF statement before redirecting to the profile page:
!HttpContext.Current.User.HasProfile() && Request.Path != "/system/profile" && !Request.Path.Contains(".")
, ( ), URL ( javascript css ). ? , , ?