Question

I have some images in my ASP.NET MVC 3 project that only certain users can view, based on some rules from the database.

In my Global.asax, in method Application_BeginRequest () I added the rules, as the following image: http://i.imgur.com/9a2rEKF.png

The code is working, if the user doesn't have permission, I show a generic image from placehold.it. However, with a libray that map sql queries, each request on my website is firing AuthorizeImage event several times (more than 50), which makes the image display slow and affect the system as a whole.

My question is: I am putting the AuthorizeImage event in the wrong place? Is there any way around this, making each image fire just one AuthorizeImage event?

Était-ce utile?

La solution

You should register event handlers during Application_Start, so they are only added once.

Registering your event handler during End_Request means that every request will cause another duplicate handler to be added.

AuthorizeImage isn't being fired 50 times; 50 copies of your handler are being registered with it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top