Inside the Begin Request event, a handler is not defined for a specific URL.
Thus, there is no way to determine what actually ends up processing this URL, since IIS has yet to be resolved. This happens after the Begin Request is run, so all file types are called.
One of the reasons Begin Request is not a good event to actually execute code requires target specific .NET files. A good use of the Begin Request method is to add cookies or headers to the request or response. You can resort to them without problems, regardless of what ends with the processing of the request.
As mentioned earlier, I suggest a base class that inherits from System.Web.UI.Page that inherits all of your other pages, or create a master page.
Now, not knowing that you are trying to do this, it is difficult to give a good solution. It may be possible to check the URL to see if it will be launched by the Route, but I don't know how this also seems excessive when you can handle it through the base class or the main page.
source share