我们正在构建一个使用基本身份验证的 ServiceStack API。我目前在我的 AppHost 中设置了身份验证,如下所示:
var authDb = new OrmLiteConnectionFactory("Server=(...);", true, MySqlDialectProvider.Instance);
var authRepo = new OrmLiteAuthRepository(authDb);
authRepo.CreateMissingTables();
container.Register<ICacheClient>(c => new MemoryCacheClient());
container.Register<IUserAuthRepository>(c => authRepo);
Plugins.Add(
new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() })
);
当执行没有授权标头或错误的用户名+传递的请求时,响应是重定向到 /Account/Login.aspx?ReturnUrl=...
部分请求 + 响应示例:
POST http://localhost:60278/reserve HTTP/1.1
HTTP/1.1 302 Found
Location: /Account/Login.aspx?ReturnUrl=%2freserve
X-Powered-By: ServiceStack/3,924 Win32NT/.NET
有没有办法让它只响应 HTTP 401 Unauthorized 或 HTTP 403 Forbidden ?