[英]Creating a FormsAuthentication with userdata inside an ASP.NET MVC Web API
I'm trying to create a FormsAuthentication inside a Web API MVC 4 with inserting userdata. 我正在尝试通过插入用户数据在Web API MVC 4中创建FormsAuthentication。 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. 在我的Web API中,我没有对象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的核心,它们始终可以通过某种方式访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.