gpt4 book ai didi

asp.net - 使用 servicestack 防止 401 更改为 302

转载 作者:行者123 更新时间:2023-12-01 02:23:01 25 4
gpt4 key购买 nike

我对 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...

}

关于asp.net - 使用 servicestack 防止 401 更改为 302,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18858653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com