【发布时间】: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