In ASP. NET, configure the following in Web. config:
<Authentication mode = "forms">
<Forms loginurl = "login. aspx"/>
</Authentication>
<Authorization>
<Deny users = "? "/>
</Authorization>
You can redirect access to any page by a user not logged on to the login. ASPX page. In login. aspx, you can use formsauthentication. redirectfromloginpage to redirect to the original page.
However, sometimes users need to be directed to other pages.
Two methods:
The first is to use formsauthentication. setauthcookie, and then write code redirect to other pages.
Another method is to redirectfromloginpage Based on the returnurl =... to redirect the page, we know that you can use this. request. querystring ["returnurl"] is used to access this value, but an exception is thrown. The reason is that the querystring set is read-only.
Therefore, we adopt the following methods:
Propertyinfo Info;
Info = request. querystring. GetType (). getproperty ("isreadonly", bindingflags. nonpublic | bindingflags. instance );
If (info! = NULL) info. setvalue (this. Request. querystring, false, null );
Request. querystring ["returnurl"] = "custom. aspx ";