Reputation: 1627
I have an MVC web app, which inherits and is part of a Webform framework. Part of the webform framework outputs several ASHX handlers. Which, I cannot remove with routes.clear()
, because that will remove them all together. I still need to use them.
Here is where my problem comes in, I have, <link href="@Url.Action("Index", "Styles")" rel="stylesheet" type="text/css" />
This points to a controller which generates dynamic CSS Style Attributes.
When the page renders the Url.Action
looks like this -
<link href="/MyLayout/Handlers/LoginStyleHandler.ashx?
action=Index&controller=Styles" rel="stylesheet" type="text/css">
As far as trying to ignore this route here is what I have tried. None of these work. What gives? What can I do to keep the ASHX path out of my Url.Action
HTML Helper.
routes.IgnoreRoute("{Handlers}.ashx");
routes.IgnoreRoute("{Handlers}/{resource}.ashx/{*pathInfo}");
routes.IgnoreRoute("TMW_LayoutPrototype/Handlers/LoginStyleHandler.ashx");
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
routes.IgnoreRoute("Handlers/LoginStyleHandler.ashx");
routes.IgnoreRoute("{*allashx}", new { allashx = @".*\.ashx(/.*)?" });
Using the Regex tester at http://regexpal.com/ let me know that my Regex pattern @".*\.ashx(/.*)?"
is valid. However it does not remove the handler from the MVC side of the web application.
The root of my problem stemmed from the web forms side of the application. Low-and-behold, inside the framework the MVC app inherited from laid a routing engine. So, my routes in MVC were getting placed at the bottom of the stack and the Webform routes were at the top.
The ignore routes did not work, because the routes were being created on the application_start event. Ignoring nor placing my MVC routes at the top of the stack did not work, because then I would lose Session, as well as, forms auth.
The solution was writing a constraint in the Webform routing code to stay out of my MVC application. After that all was fine in the MVC kingdom.
Upvotes: 2
Views: 1703
Reputation: 2046
try routes.Ignore instead of routes.IgnoreRoutes
Some of my handlers mapped to sub directories, so I went with the regex which has to be a full match instead of a partial
routes.Ignore("{*legecy}", new { legecy = @".*\.(aspx|ashx|asmx|axd|svc)([/\?].*)?" });
Upvotes: 5