. Net mvc3 enables different roles to use different logon pages

Source: Internet
Author: User

The title is vague and clear, that is, how to use the Form Verification Mechanism of. Net to redirect different roles to different login pages.

We all know which URL to jump to if a verification fails when setting the attributes of Form Verification. What should you do if the logon pages of different roles in the system are different?

    <authentication mode="Forms">      <forms loginUrl="~/Login" timeout="2880" />    </authentication>

In this way, the path strings of different login pages certainly have their own characteristics and are extracted for judgment.

We use a General login page for redirection. That is to say, in fact, it only performs redirection rather than real logon. On this page, we determine what features returnurl has and compare it with the features we summarized in the previous step. A user is a certain feature, at this time, manually redirect to the login page corresponding to this type of user, in mvc3:

// The logon page jumps to the processing page. // get:/login public redirectresult login () {string url = request ["returnurl"]; If (string. isnullorempty (URL) {return New redirectresult ("/user/login"); // Default User Logon page} else if (URL. tolower (). contains ("/JK") {return New redirectresult ("/jka/login" + "? Returnurl = "+ URL);} else {return New redirectresult ("/user/login "+ "? Returnurl = "+ URL );}}

In this way, the current website will be taken to the project/login page as long as it has not passed the user authentication, we can determine whether the Administrator path is based on the feature that the current website contains "Jk" (this logic is entirely determined by your own project and can be more rigorous and scientific)

Test passed

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: info-contact@alibabacloud.com 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.