如何在 ASP.NET MVC 网站中存储用户凭据
我的设置如下:
我有一个 MVC Web 应用程序 (EbWebApp),它具有对名为 EbServiceApp 的 WCF 服务的服务引用。出于身份验证的目的,我实现了一个表单身份验证方案:
用户登录到网站,然后我也向 Web 服务验证用户身份(使用表单身份验证)。为此,我创建了另一个名为 AuthService 的 Web 服务。
一切工作正常,但是当 Web 服务的表单身份验证票证过期时,我必须将用户重新登录到 Web 服务,而无需询问用户名和密码(例如,如果我在网站上为用户)。我不知道如何存储用户的凭据以供重新连接到 Web 服务。
任何帮助表示赞赏。
My settings is as follows:
I have an MVC web application (EbWebApp) which has a service reference to an WCF service named EbServiceApp. For authentication purposes I implemented a forms authentication scenario:
The user logs on to the web site, and then in turn I authenticate the user to the web service (using forms authentication) too. For this I created another web service named AuthService.
Everything works just fine but when the forms authentication ticket expires for the web service I would have to relog on the user to the webservice without asking for username and password (this scenario can happen for example if I set a persistent cookie on the website for the user). I don't know how could I store the user's credentials to be available for reconnection to the web service.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
警告!警告!警告!
每当您想到“我如何存储用户凭据以便稍后自动登录?”那么你正在做一些非常危险的事情。如果您可以稍后登录它们,那么有人就可以窃取这些凭据。这总是是一个坏主意。
如果表单身份验证票证过期,则只有最终用户应该能够重新登录。否则,您就违背了票证过期的目的。如果您希望票证的有效期更长,只需将其到期时间设置得更长即可。
Warning! Warning! Warning!
Whenever you think "How can i store the users credentials so i can automatically log them in later?" then you are doing something very dangerous. If you can log them in later, then someone can steal those credentials. It's ALWAYS a bad idea.
If the forms authentication ticket expires, then only the end user should be able to log himself back in. Otherwise, you're defeating the purpose of a ticket expiry. If you want the ticket to last longer, then just set its expiration to be longer.