小编Mag*_*gge的帖子

ServiceStack身份验证失败时,不重定向?

我们正在构建一个将使用基本身份验证的ServiceStack API.我目前在AppHost中设置了auth,如下所示:

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() })
);
Run Code Online (Sandbox Code Playgroud)

当执行没有Authorization标头或错误用户名的请求时+传递响应是重定向到/Account/Login.aspx?ReturnUrl = ...

Parital request + response示例:

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
Run Code Online (Sandbox Code Playgroud)

有没有办法让它只响应HTTP 401 Unauthorized或HTTP 403 Forbidden?

.net authentication servicestack

10
推荐指数
1
解决办法
4131
查看次数

标签 统计

.net ×1

authentication ×1

servicestack ×1