Multiple authentication types

5

In my system I need to have two types of authentication for Common User that will register and etc ... and another for the administrator my question is how do I differentiate the two authentication using FormsAuthentication, I believe it will have some conflict for example when I store the values in:

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

I searched for some examples on Google but did not get much success! I understood more or less that it would be necessary to create different rules.

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

    
asked by anonymous 20.05.2014 / 16:20

1 answer

3

Depending on your question, you are already using ASP.NET Form Authentication.

To implement different roles 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 role group like this:

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

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

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

link

A sample application that uses these frameworks is the MVC Music Store, found at:

link

    
20.05.2014 / 18:22