10
我們正在構建將使用基本身份驗證的ServiceStack API。我目前正在建立權威性在我APPHOST如下:當ServiceStack身份驗證失敗時,請不要重定向?
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= ...
Parital請求響應+例如:
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
有沒有一種方法,使之401未授權或HTTP 403禁止只用HTTP響應?
我認爲必須有一些ASP.net的東西在這裏混淆了我。我在文檔中看到它,並嘗試了HtmlRedirect = null,並且我使用application/json作爲Accept/Content-type標頭。重定向與您寫入(〜/ login)不同,但是/Account/Login.aspx。我會通過我的global.aspx和東西,讓你知道。 我現在接受你的回答,不過,這是SS正確設置時的解決方案。謝謝! :) – Magge
是的,這是我的不好。我的Web.config中仍然有.net成員身份,似乎覆蓋了SS身份驗證。我刪除它之後就像一個魅力。 – Magge
我懂了! ... :) –