【发布时间】:2013-09-22 09:52:18
【问题描述】:
我对 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)
});
}
}
非常感谢
【问题讨论】:
-
嗨@SeanH,请问让服务器响应302而不是401是否是一个安全问题?这种变化的原因是什么?谢谢
-
@MaRco85 我不这么认为。这是一个restful API,所以使用302重定向到登录页面是没有用的。话虽如此,服务器仍然不会授予您访问所请求资源的权限,因此从这个意义上说是安全的。如果您的客户端返回 HTTP 401,您可以合理地确定存在身份验证问题并采取措施修复它。
-
正是我的想法。非常感谢您的解释! :-) @SeanH
标签: asp.net mono servicestack http-status-codes