ASP.NET MVC - 重定向到正确的成员资格提供程序
我有一个具有买家和卖家功能的 ASP.NET MVC 3 应用程序。买方和卖方的“安全”数据库是分开的,并且每个数据库都有不同的会员提供商(具有不同的要求)。 MVC 应用程序分为多个区域,一个用于买家,一个用于卖家(添加了一些常见的内容)。现在一切正常,因为我为买家和卖家提供了不同的登录屏幕。要求发生了变化,我需要为买家和卖家使用相同的登录屏幕(和重置密码屏幕)。
理想情况下,我希望流程如下:
- 买家或卖家输入他们的电子邮件地址和密码
- 提交表单后,一个名为“操作”的常见控制器操作会
- 调用逻辑来查看买家表。如果此电子邮件地址存在,则重定向到买家帐户控制器中的登录操作。
- 否则,如果卖家表中存在电子邮件地址,则重定向到卖家帐户控制器中的登录操作
理论上,这应该可以正常工作。但是,我知道不可能使用 POST 请求重定向到另一个操作。
我想知道的是:
- 是否有任何理由不将我的买家/卖家登录操作更改为使用 GET 而不是 POST,因为它们不会在我的代码中的其他任何地方被调用?这看起来像是一个黑客,但我不知道为什么......
- 你能想出一个更好的方法来实现我想要实现的目标吗?
预先感谢,
JP
I have an ASP.NET MVC 3 application with buyer and seller functionalities. The buyer and seller 'security' databases are separated and there are different membership providers (with different requirements) for each. The MVC application is broken into areas, with one for buyers and one for sellers (with the addition of some common stuff). Everything is working fine right now as I have different login screens for buyers and sellers. A requirement has changed whereby I need to use the same login screen (and reset password screen) for both buyers and sellers.
Ideally I would like the process to flow as follows:
- Buyer or seller enters their email address and password
- Upon form submission a common controller action is called
- Action calls logic to look in buyer table. If this email address is present, redirect to logon action in buyer account controller
- Else, if email address is present in seller table, redirect to logon action in seller account controller
In theory this should work fine. However, I am aware that it is not possible to redirect to another action using a POST request.
What I would like to know is:
- Is there any reason not to change my buyer/seller logon actions to use GET rather than POST given that they will not be called anywhere else in my code? It seems like a hack, but I don't know why...
- Can you think of a better way to achieve what I am trying to achieve?
Thanks in advance,
JP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该有一个 LoginController。它只能有一个
Authorize(string email, string password)
操作。进行“拆分”的方法是创建一个MembershipProviderFactory
(或任何您想命名的名称),它将IMembershipProvider
接口返回到您的控制器。工厂可以通过查询数据库返回正确类型的MembershipProvider
。You should have a single LoginController. It can have just one
Authorize(string email, string password)
action. Where you do "the split" is by creating aMembershipProviderFactory
(or whatever you want to name it) that returns anIMembershipProvider
interface to your controller. The factory can return the correct type ofMembershipProvider
by querying the databases.