asp.net – 使用servicestack阻止401更改为302

我对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)
        });
    }
}

非常感谢

最佳答案 你几乎就在那里.

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

//... more config stuff...

}
点赞