Multiple types of authentication

Asked

Viewed 303 times

5

In my system I need to have two types of authentication one for common user who will register and etc.. and another for the administrator my question is how I differentiate the two authentication using Formsauthentication, I believe that will have some conflict for example when I save the values in:

FormsAuthentication.SetAuthCookie(user.UserName, model.RememberMe);

I looked for some examples on Google but I was not very successful! I understood more or less that it would be necessary to create different rules.

Anything will be welcome! examples, links, articles ...

  • 1

    For example when I put the [Authorize] attribute in my action how it will know which type of user it will authorize?

  • 3

    Which version of your Aspnetmvc ? has a solution yes !!! will only depend on the version itself!

  • I’m using Aspnetmvc 4! @Crood can pass some link or example of how to do this?

  • 1

    take a look at this project https://github.com/cleytonferrari/LoginMemberShip has a practical example of CustomRules

  • Just one more detail I need both users to have independent sessions being possible to exist both at the same time! you can do this with Customrules ?

  • Yes because in my project the "Administrator" Entity is different from the "User" entity and both will have access to different intefaces! I think if both users will have access to different interfaces in the system, maybe the solution is to create another project in the same Solution for the administrative part?

Show 1 more comment

1 answer

3

According to your question, you are already using the ASP.NET Form Authentication..

To implement different functions for your users (Administrator, User), you can use Membership Roles.

For example:

Authorize(Roles="Administrator")]
public ViewResult Edit(int id)
{
    return View("Edit");
}

You can check if the user is in a group of functions like this:

if (User.IsInRole("Administrator"))
{
    ...
}

To use Membership Roles, after you create a Web Application in Visual Studio, sign in to the ASP.NET configuration site and add the functions according to your application.

A good tutorial can be found on the ASP.NET website itself:

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-7

An example application using these frameworks is the MVC Music Store, found on:

http://mvcmusicstore.codeplex.com

Browser other questions tagged

You are not signed in. Login or sign up in order to post.