【问题标题】:OWIN Invalid URI: The Uri String is too longOWIN 无效 URI:Uri 字符串太长
【发布时间】:2016-01-05 23:35:20
【问题描述】:

我有一个 MVC 应用程序托管在指向 3 个 SQL 数据库的服务器 (IIS) 上。这已经运行了几个月没有问题。

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

现在当我尝试登录时,出现以下错误..

连接字符串正在使用 Windows 身份验证,并且此帐户已在 AppPool 中设置。我还手动尝试使用该帐户连接到每个数据库实例,并且效果很好。我开始认为变化是 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 抱歉,我应该一开始就包括在内。
  • 你试过 Fiddler 或 F12 等来捕获浏览器和服务器之间的 http-requests 吗?

标签: sql-server asp.net-mvc iis owin


【解决方案1】:

经过数小时的调查,我最终发现了问题。

问题在于为用户添加的声明数量。一旦我们减少了索赔数量,它就会重新开始工作。

【讨论】:

    【解决方案2】:

    最可能的原因是您陷入了错误循环。如果对存储用户的数据库的身份验证失败,那么您将被发送到错误页面,该页面将尝试再次运行身份验证并失败并一次又一次地将您发送到错误页面。每次传递都会附加到上一个 url 最终达到这个状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-05
      • 2021-11-28
      • 2021-10-26
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      相关资源
      最近更新 更多