Re-specify the page to which formsauthentication redirect is sent

Source: Internet
Author: User

In ASP. NET, configure the following in Web. config:

<Authentication mode = "forms">
<Forms loginurl = "login. aspx"/>

<Deny users = "? "/>

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 ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.