如何将 FormsAuthentication.SetAuthCookie 从数据访问层类传递到 WebService 再到 Javascript?
我在 ASP.Net 网站中使用 DotNetOpenAuth。我使用相同的方法和数据库结构对其进行了修改,使其也可以与 Facebook Connect 一起使用。现在我遇到了一个问题。
我已将 Facebook Connect 按钮添加到登录页面。通过该 HTML 按钮,我必须以某种方式从 Facebook Connect 连接中提取信息并将其传递到方法中以对用户进行身份验证。我目前执行此操作的方法是:
- 在 FBML/HTML Facebook Connect 按钮的 onlogin 函数上调用 Javascript 函数。
- javascript 函数调用 Web 服务进行登录,它执行得正确。
- Web 服务调用我的数据访问层进行登录。
- 问题是:FormsAuthentication.SetAuthCookie 是在数据访问层设置的。 Cookie 超出了用户页面的范围,因此不在浏览器中设置。
这意味着用户已通过身份验证,但用户的浏览器永远不会收到通知。
因此,我需要弄清楚这是否是一种不好的方法来完成我需要的事情,或者是否有更好的方法来完成我需要的事情。我只是不确定,并且几个小时以来一直在努力寻找答案。如果您有任何帮助,那就太好了。
I am using DotNetOpenAuth in my ASP.Net Website. I have modified it to work with Facebook Connect as well, using the same methods and database structures. Now I have come across a problem.
I have added a Facebook Connect button to a login page. From that HTML button, I have to somehow pull information from the Facebook Connect connection and pass it into a method to authenticate the user. The way I am currently doing this is by:
- Calling a Javascript Function on the onlogin function of the FBML/HTML Facebook Connect button.
- The javascript function calls a Web service to login, which it does correctly.
- The web service calls my data access layer to login.
- And here is the problem: FormsAuthentication.SetAuthCookie is set at the data access layer. The Cookie is beyond the scope of the user's page and therefore is not set in the browser.
This means that the user is authenticated, but the user's browser is never notified.
So, I need to figure out if this is a bad way of doing what I need or if there is a better way to accomplish what I need. I am just not sure and have been trying to find answers for hours. Any help you have would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,听起来你正面临一场设计危机,因为你试图在同一时间/在一个地方做太多事情。
如果您将此操作分成来自客户端的两个调用,您会发现您的选择范围很大。这可能需要更多的工作,但最终代码会变得不那么复杂。 <-- 一件好事。
在我看来,指向设计危机的第一个线索是当我对自己说“自己,在我的 DAL 中埋藏了两个调用的身份验证方法并没有按照我想要的方式工作......”哈哈。 ……我一边开玩笑一边认真。
祝你好运。
Yes, it sounds like you are having a design crisis brought on by trying to do too much at one time/in one place.
If you break this operation up in to two calls from the client you will find your options opening up quite a bit. It might take some more work but ultimately the code will be less complex. <-- a good thing.
And in my opinion, the first clue pointing to a crisis of design would be when I said to myself "Self, having an authentication method buried two calls deep in my DAL is not working the way I would like...." lol.... I am joking and serious same time.
Good luck.