0

Before starting, I see many answers for MVC but I'm not using MVC.

I just want this but for WebForms, not MVC.

For a hybrid Classic ASP/ASP.NET WebForms project, I'm trying to setup simple routing rules with RouteTable.Routes.MapPageRoute in global.asax, like this:

Protected Sub Application_Start()
   '...
   RouteTable.Routes.MapPageRoute("Projects", "friendly_link", "~/ugly/internal/stuff.asp")
   '...
End Sub

I'm not even trying to map parameters, just simple redirections because I want to avoid having a large URL rewrite section in web.config. Setting the above up gives me this:

There is no build provider registered for the extension '.asp'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

However, as I understand it, that would be processing via ASP.NET which I don't want, I want it processed by classic asp.dll.

I tried setting up the handler in web.config thus:

<system.webServer>
  <handlers>
    <remove name="ASPClassic" />
    <add name="ASPClassic" preCondition="integratedMode" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%IIS_BIN%\asp.dll" resourceType="File" />

But that gives me a 404.2 "The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server."

So how do I route Classic ASP back to ASP.dll after having passed through global.asax?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • You need to add build provider for ."asp" files, compilation section of the web.config. Something like – Vasya Jul 17 '23 at 18:19
  • @Vasya Thanks for your attention. That makes the server try to interpret is a JSript I think as I get "Compiler Error Message: JS1160: The list of attributes does not apply to the current context" – MPelletier Jul 17 '23 at 20:05
  • It seems that a wrong content type is being passed. You may have to implement custom route handler for these routes to pass the correct type, I think it's text/html for asp files. Better yet, why not create an aspx page which will simply perform response.redirect to whatever asp page is passed as a parameter in the MapPageRoute? – Vasya Jul 18 '23 at 01:27
  • You could have a custom 404 page (either in classic asp or asp.net) which can read the url of the request and use `Server.Transfer` to call up the relevant page. I suspect though that the url rewrite module could be your best option, even if it isn't ideal. It does support wildcards which might reduce the number of rules you need to add. – John Jul 18 '23 at 11:49
  • I just want [this](https://stackoverflow.com/questions/33220476/how-to-create-an-mvc-route-to-intercept-classic-asp-urls) but for WebForms, not MVC. – MPelletier Jul 18 '23 at 12:59
  • The question you link to is more or less the same one you're asking. If you read the second answer it's clear that Routes.MapRoute and Routes.MapPageRoute only work within asp.net. You can start with an empty MVC site, drop legacy aspx webform pages in and route to them, but if you drop in a classic asp page, or a php page then it will try to render it as asp.net and fail. The two options he suggests are the url rewrite module and that mikesdotnetting.com solution, which looks very complicated – John Jul 18 '23 at 13:36
  • @John Is there another type to use for the handler for webforms, equivalent to System.Web.Mvc.MvcHttpHandler for MVC? – MPelletier Jul 18 '23 at 14:29
  • 1
    Not that I know of. Webforms predate the fashion for friendly urls, they're from the era of addresses like mydomain/mypage.aspx?param1=x&param2=y – John Jul 18 '23 at 15:32

0 Answers0