asp.net mvc 在表单身份验证后存储用户名/其他 ID 信息,以便与无状态 wcf 服务进行通信
我已经查看了该网站上的一些类似问题,但找不到适合我情况的答案。
我正在使用 asp.net mvc,它与无状态 wcf 服务安全地通信。对于每个服务调用,我需要传入用户名和一些其他整数以用于识别目的。 - 不是密码,服务不进行身份验证。
我正在使用表单身份验证来验证用户身份。我只是不确定用户登录后,我应该在哪里存储他们的用户名和其他帐户详细信息,用于用户登录网站的时间范围。针对网络表单应用程序的建议包含在“会话”中。 MVC 中有等效的替代方案吗?将信息存储在表单身份验证 cookie 中是最好的解决方案吗?与内存中的其他地方相比,将这些信息保存在 cookie 中似乎会很慢..
谢谢
I have reviewed some of the similar questions on this site but could not find one with an answer appropriate for my situation.
I am using asp.net mvc, and it is communicating securely with stateless wcf services. for each service call, i need to pass in the username and a few other ints for identification purposes. - not password, the services are not authenticating.
I am using forms auth to authenticate the users. I am just not sure where, after the user logs in, I should store their username and other account details used for the scope of the user's time logged into the site. suggestions for webforms apps include in "Session". Is there an equivilent alternative in MVC? is storing the info in the forms auth cookie the best solution? it seems like it would be slow to have that info in a cookie as opposed to somewhere else in memory..
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要一遍又一遍地访问有关当前用户的选定的一些信息,您可以将 FormsAuthentication 与自定义主体实现结合起来。
Forms 身份验证机制会将 cookie 写入客户端磁盘,并根据该 cookie 为每次调用重新创建自定义主体。例如,您可以存储诸如用户“级别”、用户“个人资料”或其他小块信息之类的内容,然后可以在 HttpContext.Current.User 的生命周期内随时通过 HttpContext.Current.User 访问这些信息。您的要求。
查看有关以下主题的资源:
,我确信谷歌搜索或搜索“ASP.NET 自定义主体”将为您带来更多点击!
If you need access to a select few bits of information about the current user over and over again, you could combine FormsAuthentication with a custom principal implementation.
The Forms authentication mechanism will write a cookie to your client's disk, and will recreate the custom principal based on that cookie for each call. You could e.g. store something like a user "level", a user "profile" or other small chunks of information, which would then be accessible through the
HttpContext.Current.User
at any time during the lifetime of your request.Check out these resources on the topic:
and I'm sure googling or binging for "ASP.NET custom principal" will render quite a few more hits for you!
是的,除非信息量很大,否则首选位置是将其存储在 cookie 中。除此之外,会议是下一个最佳场所。
yes, unless it's a lot of information, the preferred location is to store it in the cookie. Aside from that, session is the next best place.