How to use multiple cookies for authentication for one application

I am writing a content management system where a user can create several sites within an application. Each site can have authentication. I am trying to figure out how to have multiple authentication cookies for an application without adding them to the web.config file. I need to create them programmatically when the application starts. Is it possible?

Ref.

SecureApp: http: // localhost / CTMS - Authentication required to update sites

CustomSite: http: // localhost / CTMS / Custom1 - Requires authentication separate from SecureApp

Hope this makes sense.

+5
source share
1

-

FormsAuthenticationTicket _ticket = new FormsAuthenticationTicket(_version, _name, _issueDate, _expirationDate, _isPersistent, _userData, _cookiePath);

string _encryptedTicket = FormsAuthentication.Encrypt(_ticket);

HttpCookie _cookie = new HttpCookie("customticket", _encryptedTicket);

HttpContext.Current.Response.Cookies.Add(_cookie);

, , cookie -

HttpCookie _cookie = HttpContext.Current.Request.Cookies["customticket"];

if(_cookie){

_encryptedTicket = _cookie.Value;
FormsAuthenticationTicket _ticket = FormsAuthentication.Decrypt(_encryptedTicket);

    if(!_ticket.Expired) {
        IIdentity _identity = new FormsIdentity(_ticket);
        IPrincipal _principal = new GenericPrincipal(_identity, new string[0]); //Identity plus string of roles.
    }
}
else{
//dostuff
}
+8

All Articles