public static void SetAuthInfo(Guid Id, string Email, string FullName, string Role, Guid PersonId, Guid OrganizationId
, string exchangeUID, string exchangePWD, string exchangeDomain,int? fileManagerPermission)
{
if (HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName] != null)
{
HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
}
string fullName = FullName;
var ticket = new FormsAuthenticationTicket(
1,
fullName,
DateTime.Now,
DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
false,
string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}", Email, Id, FullName, Role, PersonId, OrganizationId, exchangeUID,
July.Common.Encryption.Encrypt(exchangePWD), exchangeDomain, fileManagerPermission==null?0:fileManagerPermission));
var encryptedTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
{
HttpOnly = true,
Secure = FormsAuthentication.RequireSSL
};
var ASPSESSID = new HttpCookie("ASPSESSID")
{
HttpOnly = true,
Secure = FormsAuthentication.RequireSSL,
Expires = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes)
};
var identity = new GenericIdentity(ticket.Name);
var principal = new CustomUserPrincipal(identity, Id, Email, Role, FullName, PersonId, OrganizationId, exchangeUID, exchangePWD, exchangeDomain);
HttpContext.Current.User = principal;
}
The above code will be used to set the authentication info after login. In web.config file, you need to add the following nodes.
<authentication mode="Forms">
<forms defaultUrl="~/Home/Index" timeout="30" name="FormsAuthentication" loginUrl="~/Account/Login" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
Then create a page for login. validate in and if validate then store the data by above SetAuthInfo.