0

I need a way to differentiate Document requests (that return actual DOM - the very first request when you visit a page), from all other requests i.e ajax, controller actions, etc.

Based on MS Docs, Authorization is hit first in the pipeline. So i want to implement a filter:

public void OnAuthorization(AuthorizationContext filterContext) 
{
// check if this is a DOM request, and do something
}

I want this check to be particularly in Authorization filter because it's the first in the pipe, and it would be most efficient to do the thing before all other filters execute.

I checked all the details in filterContext and couldn't find anything i can rely on. If it's not possible in Authorization filter, i am curious about how it can be solved in other filters.

TValerii
  • 160
  • 1
  • 6
  • What's the purpose ? more explanation would help to understand your problem – HariHaran Nov 22 '19 at 10:17
  • @HariHaran the purpose is to check if it's a specific DOM request and redirect to another url. (i know we could use other tools like URL Rewrite, but the rest of the logics is in the filter, and only this piece with DOM requests is missing) – TValerii Nov 22 '19 at 10:34
  • While Authorization is the first in the pipeline, I'd sacrifice a millisecond or two to make sure you put the code in the most-correct location. The code you want to write doesn't do anything related to authorization, so consider putting it in its own action filter. FWIW, you can specify the order of execution of your custom filters using the `Order` parameter. See ProVega's answer here https://stackoverflow.com/questions/6561883/in-what-order-are-filters-executed-in-asp-net-mvc – trademark Dec 11 '19 at 18:38
  • As far as accomplishing your goal, it looks like this might be a good start for you. The implementation could be cleaned up a bit but this is the right approach. https://stackoverflow.com/a/14886810/5354201 – trademark Dec 11 '19 at 18:42

0 Answers0