在.NET中自动分配身份验证令牌
我已经使用 .NET 会员提供程序实现了表单身份验证,但我也希望用户能够使用 Facebook 登录。通过 Facebook 进行身份验证后,我想自动向用户分配 .NET 身份验证令牌。我有一个 HttpModule 正在检测 FB 身份验证,但我所有手动生成身份验证令牌的尝试都失败了。
我尝试了
FormsAuthentication.SetAuthCookie
FormsAuthentication.GetAuthCookie
+Response.Cookies.Add
new FormsAuthenticationTicket(...)
a la MSDN- 在
HttpModule< /code> 与
Page
以及其他一些绝望的尝试。似乎什么都不起作用。这是怎么做到的?
I have implemented forms authentication with a .NET Membership Provider but I also want users to be able to login with Facebook. Once authenticated with Facebook, I want to automatically assign a .NET authentication token to the user. I have a HttpModule
that is detecting the FB authentication but all my attempts to manually generate an authentication token have come up short.
I tried
FormsAuthentication.SetAuthCookie
FormsAuthentication.GetAuthCookie
+Response.Cookies.Add
new FormsAuthenticationTicket(...)
a la MSDN- In an
HttpModule
vsPage
Plus a few other desperate attempts. Nothing seems to work. How is this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
建议的方法是使用 WIF
Proposed way is using WIF
在
SetCookieAuth
后,您需要执行重定向以使 HttpModule 有机会触发并设置HttpContext.User
属性。After you
SetCookieAuth
you need to do a redirect to give the HttpModule a chance to fire and set theHttpContext.User
property.事实证明,其他人在解决方案中注册了另一个模块,该模块干扰了 HttpRequest 和身份验证部分。在我摆脱它之后,
FormsAuthentication.SetAuthCookie(...)
工作正常。感谢大家的帮助。
It turns out someone else had registered another module in the solution that was interfering with
HttpRequest
and the authentication pieces. After I got rid of that,FormsAuthentication.SetAuthCookie(...)
worked fine.Thanks everyone for the help.