我应该如何在我的 Asp.net MVC 应用程序中处理授权/身份验证?
我正在创建一个 Asp.net MVC 应用程序,目前正在使用示例 MVC 应用程序附带的内置身份验证/授权代码。在大多数情况下,这工作正常,我有点明白发生了什么。
但令我担心的是,现在我将用户存储在两个数据库的两个不同表中。即,我的应用程序数据库中有用户,代表应用程序中的“客户”实体,以及身份验证数据库中的“用户”,用于将某人登录到应用程序。
我应该获取登录用户的 User.Identity.Name 值并在我的 Customers 表中查找还是应该将它们合并到一个表中?处理这个问题的最佳实践方法是什么?
请原谅我的无知 - 这是我第一次使用这样的系统。
非常感谢任何反馈!
I am creating an Asp.net MVC application and I'm currently using the built in Authentication/Authorization code that comes with the sample MVC app. For the most part this is working ok and I kinda understand what's going on.
What's concerning me though, is that now I kind of have my users stored in two different tables across two databases. i.e. I have users in my App's database that represent the "Customer" entity in the application, as well as the "User" in the Authentication database that's used to log in someone to the app.
Should I take the logged in user's User.Identity.Name value and do look up in my Customers table or should I merge them into one table? What's the best practice way of handling this?
Please forgive my ignorance - this is the first time I'm working with a system like this.
Any feedback is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将凭证和将人员与应用程序数据相关联的记录视为两个截然不同的事物会很有帮助。根据应用程序的不同,您的客户可能没有登录凭据,或者您可能拥有登录但与您的应用程序数据无关的管理用户。
如果用户访问多个应用程序且每个应用程序具有不同的权限,则单独的凭据也很有用。
出于这些原因,我会将客户和用户分开,并在适当的情况下查找其中一个。
It's helpful to think of credentials and the records that associate a person to application data as two very different things. Depending on the application, your Customer may not have credentials to log in or you may have an administrative User that logs in but isn't related to your application data.
Separate credentials are also useful if Users access more than one application with different rights for each.
For these reasons, I'd keep Customer and User separate and look one up from the other where appropriate.
我认为您可以扩展 .Net Membership Provider 以获取您想要的所有信息并在单个模型中发回。
请参阅此 ASP.net配置文件和会员资格 - 自定义提供商还是应该完全由我自己推出?
而这个 如何在我的域模型中实现 ASP.NET 成员资格提供程序
You can extend the .Net Membership Provider to take all the information you want and post back in a single model I think.
See this one ASP.net Profiles and Membership - Custom Providers or should completely I roll my own?
And this one How to implement ASP.NET membership provider in my domain model