Authentication for multiple users with ASP.NET MVC and .NET 4.5

0

I am developing a system where there is a need for two types of users, the client, which will only access the frontend , and the administrator associated with backoffice . I need these users to be authenticated in different "cookies", since they are part of different areas.

I've been seeing about FormsAuthentication.SetAuthCookie , but it seems like there's no way to assign a different ID to the authentication cookie for this function.

Could you give me an idea of where to start?

Note: I'm looking for a method that I can keep separate sessions without the need to use Roles to maintain access to the frontend and backoffice panel associated with your user type. Because I have two forms of authentication (one for the client and one for the administrator) and separate by Roles would be an "obstacle", in addition, it will probably be common for an administrator to also have a user account and vice -versa, and want to authenticate in both at the same time. Therefore keeping separate endorsements will provide more flexibility in these cases.

    
asked by anonymous 29.02.2016 / 20:00

1 answer

1

You can use different cookies names for different logins. That way one cookie will not overwrite another.

You can set the cookie value in the Web.config file by changing the value of the "name" attribute:

<authentication mode="Forms">
 <forms name=".NomeDoCookie" domain="seudominio.com" ... />
</authentication>

But to have two different names, you would need to do the authentication manually, using different values for the cookiePath attribute:

FormsAuthentication.GetAuthCookie(username, false, "cookiePath");
FormsAuthentication.SetAuthCookie(username, false, "cookiePath");

In this way, each type of user would be authenticated independently.

I hope I have helped.

    
18.03.2016 / 17:24