我正在尝试在插入userdata的Web API MVC 4中创建FormsAuthentication。我知道如何在客户端进行。
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);
在我的Web API中,我没有对象Response。
FormsAuthentication.SetAuthCookie(model.UserName, false);
但它没有给我添加用户数据的可能性。
答案 0 :(得分:0)
HttpContext.Current.Response
Request
和Response
个对象是ASP.NET的核心,它们始终以某种方式可访问。