簡體   English   中英

在ASP.NET MVC Web API中使用用戶數據創建FormsAuthentication

[英]Creating a FormsAuthentication with userdata inside an ASP.NET MVC Web API

我正在嘗試通過插入用戶數據在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);

但這並沒有給我添加用戶數據的可能性。

HttpContext.Current.Response

RequestResponse對象是ASP.NET的核心,它們始終可以通過某種方式訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM