我用CookieAuthentication在我與owin的應用程序,並設置OnApplyRedirect
重定向URL如下面的代碼:Owin:OnApplyRedirect打過幾次電話,並創建不正確RedirectUri
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
ExpireTimeSpan = TimeSpan.FromDays(30),
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/account/sign-in"),
//LogoutPath = new PathString("/account/log-out"),
ReturnUrlParameter = "returnTo",
CookieName = "BIR",
Provider = new CookieAuthenticationProvider()
{
OnValidateIdentity = SmObjectFactory.Container.GetInstance<IAppUserManager>().OnValidateIdentity(),
OnApplyRedirect = c =>
{
if (!c.Request.IsAjaxCall())
{
c.Response.Redirect(c.RedirectUri);
}
}
}
});
我的問題是c.RedirectUri
值,我設置斷點點和追蹤我的代碼後做到這一點,我明白,OnApplyRedirect
稱爲服務時間。
在第一次調用RedirectUri
是:
http://localhost:7537/account/sign-in?returnTo=%2Fadmin-panel
在第二次調用RedirectUri
是:
http://localhost:7537/account/sign-in?returnTo=%2Faccount%2Fsign-in%3FreturnTo%3D%252Fadmin-panel
和更多...
在預先調用舊URL添加新的URL。 我試圖解決這個問題,在另一個和當前的網站搜索和研究,但沒有找到答案,爲什麼OnApplyRedirect
多次調用? Configuration
方法Startup.cs
類只調用一次。 其他細節:
- Owin版本:3.1.0
- ASP.NET MVC版本:5.x的
的Visual Studio版本:2017年(15.2)
只是爲了確保'/ account /登錄'不需要驗證。 即它用'[AllowAnonymous]裝飾' – Albert