Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用returnUrl的每个模块身份验证_C#_Authentication_Nancy - Fatal编程技术网

C# 使用returnUrl的每个模块身份验证

C# 使用returnUrl的每个模块身份验证,c#,authentication,nancy,C#,Authentication,Nancy,我需要对一些模块进行表单身份验证,对其他模块进行无状态身份验证。使用表单身份验证时,登录页面需要设置returnUrl 我们使用应用程序范围的表单身份验证(为管道启用)实现了这一点,但我们一直在尝试启用混合身份验证 根据,我们必须在模块构造函数中启用表单身份验证: public abstract class FormsAuthenticationModuleBase : NancyModule { protected FormsAuthenticationModuleBase(IUser

我需要对一些模块进行表单身份验证,对其他模块进行无状态身份验证。使用表单身份验证时,登录页面需要设置
returnUrl

我们使用应用程序范围的表单身份验证(为管道启用)实现了这一点,但我们一直在尝试启用混合身份验证

根据,我们必须在模块构造函数中启用表单身份验证:

public abstract class FormsAuthenticationModuleBase : NancyModule
{
    protected FormsAuthenticationModuleBase(IUserMapper userMapper)
        : this(userMapper, string.Empty)
    {
    }

    protected FormsAuthenticationModuleBase(IUserMapper userMapper, string modulePath)
        : base(modulePath)
    {
        var formsAuthConfiguration = new FormsAuthenticationConfiguration
        {
            RequiresSSL = false,
            UserMapper = userMapper,
            RedirectUrl = "/login?returnUrl=" + Context.Request.Headers["X-Original-URL"].FirstOrDefault()
        };

        // Enable calls RequiresAuthentication.
        FormsAuthentication.Enable(this, formsAuthConfiguration);
    }
}
问题是
上下文
在构建时为

我们如何在每个模块的基础上启用表单身份验证,并设置包含
returnUrl
RedirectUrl

(另见)

更新

根据的建议,我尝试添加一个:

(使用原始的
重定向URL=“/login”

这导致了一个405,我无法调试到其中。(与+=语法之前的
相同。)

他还建议将所有东西都放到钩子中,而不是存储配置并对其进行变异;那也没用

目前我正在使用(与上述方法相反)。这很有效。

使用works。

使用works

Before.AddItemToStartOfPipeline(
    ctx =>
    {
        if (!formsAuthConfiguration.RedirectUrl.Contains("?"))
        {
            formsAuthConfiguration.RedirectUrl +=
                "?returnUrl=" + ctx.Request.Headers["X-Original-URL"].FirstOrDefault();
        }

        return null;
    });