How do I stop the Identity Framework OWIN startup class being called for image requests?
Is it possible to prevent the Owin startup class from running for every image request in my folder /Content/Images
?
I find that the new DbContext makes a difference new
for every image request when there is no need to do authorization checks on the images.
UPDATE:
I just created a new MVC project and I found that the class is not being called for images inside /Content/images/
.
So it looks like it doesn't call it by default when it's a folder request /Content
, but for some reason in my application it does.
Is there a parameter in web.config
or properties of the folder that configures it?
source to share
In your configuration, replace runAllManagedModulesForAllRequests="true"
with runAllManagedModulesForAllRequests="false"
. If this breaks something in your application, you may need to use preCondition="managedHandler"
for registered modules, but in most cases the property should be set to false
.
See Unable to Stop ASP.NET Module Running on Static Content for how this property works.
source to share
you can try something like this and not name your config if IsStaticContent = true (I used this in global.asax but will be the same):
readonly string[] _staticContents = { ".js", ".css", ".png", ".jpg", ".jpeg", ".html", ".htm", ".gif", ".ashx", ".axd" };
protected bool IsStaticContent(HttpRequest request)
{
return _staticContents.Any(request.CurrentExecutionFilePath.EndsWith);
}
source to share