2015-10-08 59 views
6

我有一个托管在指向3个SQL数据库的服务器(IIS)上的MVC应用程序。这几个月来一直没有问题。OWIN无效的URI:Uri字符串太长

我只需要更改所有3个SQL数据库的连接字符串以指向新的数据库。

现在,当我尝试登录我碰到下面的错误..

enter image description here

连接字符串使用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); 
        } 
       } 
      } 
     }); 

    } 
} 
+0

显示你的'Startup.cs' – haim770

+0

@ haim770道歉我应该包括那开始。 – heymega

+0

您是否尝试过Fiddler或F12等来捕获浏览器和服务器之间的http请求? –

回答

1

经过数小时的调查,我终于找到了问题。

问题是为用户添加的索赔数量。一旦我们减少了索赔数量,它又开始工作。

0

最可能的原因是,你停留在一个错误循环。如果对存储用户的数据库进行身份验证失败,则会发送到错误页面,该页面将尝试再次运行身份验证并失败,并一次又一次地将您发送到错误页面。每传递一次,它就会追加到前一个最终到达此状态的url。