网站通过单独的系统进行授权。一旦用户被授权,我想用他们的Auth cookie存储一些额外的信息。我可以使用下面的代码执行此操作。
var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var serialized = JsonConvert.SerializeObject(accountNumber, Formatting.None, settings);
var authTicket = new FormsAuthenticationTicket(1, "MyAuthTicket", DateTime.Now, DateTime.Now.AddMinutes(15),
false, serialized);
var encTicket = FormsAuthentication.Encrypt(authTicket);
var faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
{
HttpOnly = true,
};
Response.Cookies.Add(faCookie);
但是,当我尝试点击标有[Authorize]的WebAPI方法时,我收到401 Unauthorized错误。我错过了什么?
答案 0 :(得分:0)
将以下需求添加到web.config:
<system.web>
<authentication mode="Forms">
</authentication>
<!-- other stuff -->
<system.web>