I'm trying to create a FormsAuthentication inside a Web API MVC 4 with inserting userdata. I know how to do it on a client side.
UserData userData = new UserData()
{
SiteID = result.UserLite.SiteID,
UserID = result.UserLite.ID,
UserName = result.UserLite.UserName,
SiteName = result.UserLite.SiteName,
TokenValue = result.BaseSecurityToken.Value,
FirstName = result.UserLite.FirstName,
LastName = result.UserLite.LastName,
Email = result.UserLite.Email,
LanguageID = result.UserLite.LanguageID
};
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
model.UserName,
DateTime.Now,
DateTime.Now.Add(FormsAuthentication.Timeout),
false,
Serialize(userData));
string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Response.Cookies.Add(faCookie);
In my Web API I don't have the object Response.
FormsAuthentication.SetAuthCookie(model.UserName, false);
But it doesn't give me the possibility to add user data.
HttpContext.Current.Response
Request
和Response
对象是ASP.NET的核心,它们始终可以通过某种方式访问。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.