【问题标题】:Different IUserMapper implementation for different modules- NancyFx不同模块的不同 IUserMapper 实现 - NancyFx
【发布时间】:2018-01-23 21:33:21
【问题描述】:

我目前正在开发一个包含两个部分的 Nancy 网站。一种用于字体最终用户,另一种用于管理员。两种类型的用户都有不同的登录页面,/login 只允许最终用户登录,admin/login 只允许管理员登录。

我想要的是IUserMapper 接口的不同实现。我希望在调用/login 时将其解析为UserMapper,并在调用/admin/login 路由时解析为AdminMapperUserMapperAdminMapper 类如下:

public class UserMapper: IUserMapper{
    //IUserMapper implementation
}
public class AdminMapper: IUserMapper{
//IUserMapper implementation
}

我在RequestStartup 方法中有以下表单验证代码

var formsAuthConfiguration = new FormsAuthenticationConfiguration()
                {
                    RedirectUrl = "~/login",
                    CryptographyConfiguration = CustomCryptographyConfiguration.Default,
                    UserMapper = container.Resolve<IUserMapper>()
                };

                FormsAuthentication.Enable(pipelines, formsAuthConfiguration);

我如何告诉 Nancy 在调用 /login 时将 IUserMapper 映射到 UserMapper 并在调用 /admin/login 时映射到 AdminMapper

【问题讨论】:

    标签: .net authentication forms-authentication nancy


    【解决方案1】:

    这必须由您自己执行。南希没有机械师能够知道如何自动处理这个问题

    当您连接表单身份验证并分配 FormsAuthenticationConfigurationUserMapper 属性时,您无法从容器中解析它。

    您将不得不根据请求的路由创建适当的IUserMapper 实例。您可以从传递给您的RequestStartup 方法的NancyContext 对象获取请求的路由。

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2016-06-25
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多