1

I would like to understand briefly how the authorize filter and FormAuthentication.SetAuthCookie work under the hood. It's the only thing I find ambiguous after reading some books on the language.

I don't understand how the authorize filter knows where to look. And what about FormsAuthenticationTicket VS FormAuthentication ? And is cookie the most secure way, I mean I'm sure it's possible to export the cookie from a browser and use it somewhere else..?

4

1 回答 1

0

你可能会发现这个问题很有帮助。

如果您对 Authorize 过滤器如何更详细地工作感兴趣,可以查看源代码:AuthorizeAttribute

简而言之,Authorize过滤器将通过检查HttpContext.User.Identity.IsAuthenticated属性来检查用户是否已通过身份验证。在表单身份验证的情况下,该User属性将由 FormsAuthenticationModule 设置。

FormsAuthentication.SetAuthCookie方法为经过身份验证的用户创建票证(假设用户提供了正确的凭据)并将其添加到响应的 cookie 集合中。或者,如果您愿意,可以将模块配置为使用无 cookie 身份验证,但加密票证仍随每个 HTTP 请求一起发送。无论哪种方式,客户端(浏览器)都需要一种方法来告诉服务器请求已通过身份验证。

关于您对安全性的担忧,这个问题有一些想法。

于 2014-01-20T16:04:16.240 回答