使用 unity 解决自定义会员资格提供程序

发布于 2024-09-30 04:45:51 字数 681 浏览 2 评论 0原文

我有一个自定义的会员资格提供程序,在我在 Web 应用程序中使用 unity 之前它工作得很好。

public class CustomMemberProvider : MembershipProvider

我做了一些谷歌搜索,发现下面的代码片段放置在全局文件的 application_start() 中,但我不确定需要对其做什么才能使其适用于我的自定义提供程序。基本上,当我在安全控制器上调用 validateUser() 时,它无法解析依赖项。

        _container.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>()
        .RegisterType<IMembershipService, AccountMembershipService>()
        .RegisterInstance<MembershipProvider>(Membership.Provider);

我认为我可以将“AccountMembershipService”交换为“CustomMemberProvider”,但这会导致标准“UnityControllerFactory”中的控制器类型为空。

有人遇到过同样的问题吗?

谢谢。

I have a custom membership provider which works fine until I use unity in the web application.

public class CustomMemberProvider : MembershipProvider

I have done some googling and found the snippet below to place in the application_start() of the global file but I am not sure what I need to do to it to make it work for my custom provider. Basically when I make a call on validateUser() on my security controller it fails to resolve the dependencies.

        _container.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>()
        .RegisterType<IMembershipService, AccountMembershipService>()
        .RegisterInstance<MembershipProvider>(Membership.Provider);

I thought I could swap "AccountMembershipService" for "CustomMemberProvider" but that causes the Controller Type to be null in the standard "UnityControllerFactory".

Has anyone had the same problems?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2024-10-07 04:45:51

AccountMembershipService 可能与 VS 生成的服务相同。该服务实现 IMembershipService(由代码生成的自定义接口)。简单地将 AccountMembershipService 替换为 CustomMemberProvider 并不是一回事。

本质上,您的自定义成员资格提供程序实现了抽象类“MembershipProvider”,它与“AccountMembershipService”不同,“AccountMembershipService”是 SqlMembershipProvider 的包装器。

您需要为您的会员资格提供者创建一个包装器来实现类型。另外,我很确定 Membership.Provider 会将您带到 System.Web.Security.MembershipProvider 而不是您的自定义提供程序。

AccountMembershipService is probably the same service that VS generates. This service implements IMembershipService (a custom interface generated by the code). Simply swapping out AccountMembershipService for CustomMemberProvider is not going to be the same thing.

Essentially, your custom membership provider implements the abstract class "MembershipProvider" which is different than this "AccountMembershipService" which is a wrapper to SqlMembershipProvider.

You need to make a wrapper to your membership provider to implement a type. Also, I'm pretty sure Membership.Provider is going to take you to System.Web.Security.MembershipProvider and not your custom provider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文