views:

22

answers:

1

I have an asp.net mvc web app that has controllers with role attributes on them for checking authenticated user roles. I ran into a problem with ajax where I have ajax "get" requests that trigger additional role and user checks each time a page is loaded up.

Right now when I load up one of my pages I have the same query running 4 times because of the ajax requests hitting the roles attributes on the controller. Does anyone know any good techniques to prevent this from happening?

Thanks

+1  A: 

How about creating a custom attribute extending asp.net mvc´s AuthorizeAttribute and checking in your implementation if the request is an Ajax request or not? Request.IsAjaxRequest

You can use the base behaviour if the request is not an ajax request, otherwise return

Regards.

uvita
I ended up using a session variable, but your answer would work.
chobo