R – Does FormsAuthenticationModule detect whether …

asp.netauthenticationforms-authenticationhttpmodulenet

FormsAuthenticationModule is used for tracking user and role information using encrypted cookie.

But does this module also contain code that actually detects whether user requesting web page has forms authentication ticket and if not, redirects user to login page, or is it actually UrlAuthorizationModule that tells FormsAuthenticationModule to redirect unauthorized/unauthenticated user to the login page?

thanx

Best Answer

Oddly enough, I just researched this this week.

It turns out that the FormsAuthenticationModule does do the actual redirect in EndRequest event handler. However, it doesn't decide that the redirect should happen. It does the redirect if the response status code is 401 (Unauthorized).

The UrlAuthorizationModule is the place where the decision is made (as mentioned in another answer), but all it does is indicate that the request is not authorized by setting the response status code to 401.

So, it is actually the two modules in coordination that make the redirect to the login page happen.