Ich benutze asp.net Identität 2 in meiner Anwendung für implementieren Identity-System. Wenn ich meine Anwendung mit EF Profiler profiliere.Authentifizierungsprüfung für statische Dateien in ASP.NET ignorieren Identität
Ich sehe ein Problem, dass es in der statischen Dateianforderung mit der Datenbank verbunden ist. Dies ist so schlecht für die Leistung und Ladegeschwindigkeit der Seite.
zur Lösung dieses Problems ich folgenden Code schreiben:
Global.asax
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (shouldIgnoreRequest())
return;
if (Context.User == null)
return;
}
private bool shouldIgnoreRequest()
{
string[] reservedPath =
{
"/__browserLink",
"/favicon.ico",
"/img",
"/css"
,"/w",
"/js"
};
var rawUrl = Context.Request.RawUrl;
if (reservedPath.Any(path => rawUrl.StartsWith(path, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
return BundleTable.Bundles.Select(bundle => bundle.Path.TrimStart('~'))
.Any(bundlePath => rawUrl.StartsWith(bundlePath, StringComparison.OrdinalIgnoreCase));
}
RouteConfig.cs
routes.IgnoreRoute("img/{*pathinfo}");
routes.IgnoreRoute("js/{*pathinfo}");
routes.IgnoreRoute("css/{*pathinfo}");
routes.IgnoreRoute("{file}.gif");
routes.IgnoreRoute("{file}.jpg");
routes.IgnoreRoute("{file}.js");
routes.IgnoreRoute("{file}.css");
routes.IgnoreRoute("{file}.png");
routes.IgnoreRoute("{file}.pdf");
routes.IgnoreRoute("{file}.htm");
routes.IgnoreRoute("{file}.html");
routes.IgnoreRoute("{file}.swf");
routes.IgnoreRoute("{file}.txt");
routes.IgnoreRoute("{file}.xml");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
Wie kann ich ignorieren diese Anfragen für Authentifizierung?
uns Konfiguration Ihrer Identity zeigen? Ich vermute, dass Ihr Sicherheitsstempel-Invalidator den Cookie bei jeder Anfrage ungültig macht. – trailmax