ASP.NET MVC 3 User Authentication

后端 未结 3 769
滥情空心
滥情空心 2021-01-30 12:11

What are some of the common methods to do simple user validation (account login)?

Also, can you have different authentication schemes per area?

Edit

3条回答
  •  野性不改
    2021-01-30 12:31

    You have several options when it comes to doing authentication in MVC:

    • The built-it MVC Forms Authentication (Tutorial available here and here)
    • Using Forms Authentication with Cookies in MVC3 (Link here)
    • Using Windows Authentication (Learn more here...)
    • Mixed Mode Authentication (Using Windows / Forms Authentication together.)

    The built in Forms Authentication can allow you to limit access to different areas of your application based on Role, User among other things and it is quite easy to implement using the [Authorize] attribute.

    The following would require the user be logged in:

    [Authorize]
    public ActionResult YourActionNameGoesHere()
    {
    }
    

    Likewise, the following would require the user be logged in AND be an Administrator:

    [Authorize(Roles="Administrator")]
    public ActionResult YourActionNameGoesHere()
    {
    }
    

    Those were just a few methods of accomplishing it, as you can see there are MANY different methods of accomplishing this - I hope this might have shed a bit of light in helping you decide.

提交回复
热议问题