使用servicestack防止401更改为302

时间:2013-09-17 19:48:23

标签: asp.net mono servicestack http-status-codes

我对servicestack很新。我似乎在将401个雕像重写为302时遇到了麻烦。我正在看这个答案:

When ServiceStack authentication fails, do not redirect?

我看到建议的解决方案是添加以下内容:

Plugins.Add(new AuthFeature(...) { HtmlRedirect = null });

我的问题是,我在哪里添加它才能让它发挥作用?我已经开始基于github上的示例构建一些东西:

public class AppHost : AppHostBase
{
    public AppHost() : base("Custom Authentication Example", typeof(AppHost).Assembly) { }

    public override void Configure(Container container)
    {
        // register storage for user sessions 
        container.Register<ICacheClient>(new MemoryCacheClient());

        // add routes
        Routes.Add<HelloRequest>("/hello"); 

        // Register AuthFeature with custom user session and custom auth provider
        Plugins.Add(new AuthFeature(
            () => new CustomUserSession(),
            new[] { new CustomCredentialsAuthProvider() }
        ));

        // Enable the metadata page
        SetConfig(new EndpointHostConfig {
            EnableFeatures = Feature.All.Add(Feature.Metadata)
        });
    }
}

非常感谢

1 个答案:

答案 0 :(得分:2)

你几乎就在那里。

public override void Configure(Container container)
{
     Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() }) { HtmlRedirect = null });

//... more config stuff...

}