【问题标题】:Creating a FormsAuthentication with userdata inside an ASP.NET MVC Web API在 ASP.NET MVC Web API 中使用用户数据创建 FormsAuthentication
【发布时间】:2013-11-21 15:14:45
【问题描述】:

我正在尝试通过插入用户数据在 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);

但我无法添加用户数据。

【问题讨论】:

  • 如果我没记错的话,那应该属于控制器代码。

标签: c# asp.net-mvc-4 asp.net-web-api forms-authentication


【解决方案1】:
HttpContext.Current.Response

RequestResponse 对象是 ASP.NET 的核心,它们总是以某种方式可访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-03
    • 2012-08-09
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    相关资源
    最近更新 更多