我有一個託管在指向3個SQL數據庫的服務器(IIS)上的MVC應用程序。這幾個月來一直沒有問題。OWIN無效的URI:Uri字符串太長
我只需要更改所有3個SQL數據庫的連接字符串以指向新的數據庫。
現在,當我嘗試登錄我碰到下面的錯誤..
連接字符串使用Windows身份驗證與此帳戶的應用程序池設置。我也手動嘗試連接到每個數據庫實例與帳戶,這工作正常。我開始認爲這種變化是SQL連接只是一個紅鯡魚。
根據錯誤信息,我完全明白錯誤是什麼,我只是不知道爲什麼它被拋出。我能想到的唯一的事情是我在某種附加URL的重定向循環中。
它絕對感覺像是一個IIS問題,但我不能把它放在手指上。
有沒有人在使用OWIN之前遇到過這個問題,或者可以建議調試可能診斷問題的步驟?
Startup.cs
public partial class Startup
{
private static bool IsAjaxRequest(IOwinRequest request)
{
IReadableStringCollection query = request.Query;
if ((query != null) && (query["X-Requested-With"] == "XMLHttpRequest"))
{
return true;
}
IHeaderDictionary headers = request.Headers;
return ((headers != null) && (headers["X-Requested-With"] == "XMLHttpRequest"));
}
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and role manager to use a single instance per request
app.CreatePerOwinContext(ParentDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.CreatePerOwinContext(PrincipalManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, Guid>(
TimeSpan.FromMinutes(int.Parse(WebConfigurationManager.AppSettings["RefreshInterval"])),
(manager, user) => manager.GenerateUserIdentityAsync(user),
claim => new Guid(claim.GetUserId())),
OnApplyRedirect = ctx =>
{
if (!IsAjaxRequest(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
}
}
顯示你的'Startup.cs' – haim770
@ haim770道歉我應該包括那開始。 – heymega
您是否嘗試過Fiddler或F12等來捕獲瀏覽器和服務器之間的http請求? –