Per-Route身份验证导致RouteExecutionEarlyExitException

时间:2014-07-03 14:15:04

标签: c# authentication nancy

我对Nancy很新,现在正在尝试使用Auth。期待完全实现Forms身份验证。

出于测试目的,我设置了3个模块。

其他模块:

public class OtherModule : NancyModule
{
    public OtherModule() : base()
    {
        // Use global, module level authentication.
        this.RequiresAuthentication();

        Get["/other"] = _ =>
        {
            return "Other";
        };

        Get["/woot"] = _ =>
        {
            return "Woot";
        };
    }
}

主要模块:

public class MainModule : NancyModule
{
    public MainModule() : base()
    {
        Get["/yolo"] = _ =>
        {
            // Use per-route authentication.
            this.RequiresAuthentication();

            return "#YOLO";
        };
    }
}

AuthModule:

public class AuthModule : NancyModule
{
    public AuthModule() : base()
    {
        Get["/login"] = _ =>
        {
            return "To proceed, you must authenticate. [show form]";
        };
    }
}

现在,当我导航到/other和/或/woot时,我会按预期重定向到/login。但是,当我导航到/yolo时,应用程序会抛出Nancy.ErrorHandling.RouteExecutionEarlyExitException,我认为它应该将我重定向到/login?returnUrl=seeme

我已经浏览了the github forms auth source,其中包含this file中的行为。我似乎无法找到任何重大差异(我的Bootstrapper,我的IUserMapper,我的IUserIdentity)。

我的用法不对吗?我应该尝试/捕获它并相应地准备响应吗?这是一个错误吗?

我在自托管环境(Nancy.Hosting.Self)中运行NancyFX,没有ASP,也没有OWIN。

1 个答案:

答案 0 :(得分:3)

虚假警报,虚警。

这是我的Visual Studio调试器,他刚刚报告了异常。

当然,像往常一样,我推了“Break”,应用程序就崩溃了。而是按“继续”,确实将我重定向到正确的页面。

相关问题