Click here to Skip to main content
15,885,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am migrating a project which contains hundreds of static htm files all of which need to be routed to new dynamic Blazor pages. This website is decades old and has many hundreds (if not thousands) of backlinks that should not be sacrificed with a generic 404 error when the new Blazor solution hosts.
While performing the Blazor migration, it does not appear as though IIS maps .htm files in ways which Blazor can reach the request in order to route or handle any custom logic.

Any suggestions?

So the brief picture:
/myproduct1.htm should route to /myproduct1
/contact.htm should route to /contact

Or better yet have Blazor perform logic and replace the standard htm result page with custom-driven content.

I hope I have made myself clear. Thank you so much for your assistance!

What I have tried:

It appears all of the standard routing does not get fired when trying to catch a .htm file. I was able to do this with the old webforms approaches of .net

Thank you again.
Posted
Updated 19-Sep-22 13:27pm
Comments
gggustafson 21-Apr-22 13:34pm    
"catch" or "cache"?
Member 15064765 19-Sep-22 18:57pm    
Catch, as in route through iis and resolve it to a logical page rather than a static page. or even catch a 404 error if the page does not exist.

1 solution

Just figured it out!

Adding this endpoint to my Startup.cs gives me access to everything I need:
endpoints.MapFallbackToPage("/{param?}", "/_Host");


For those that are 100% new, here is a more complete code snippet:
app.UseEndpoints(endpoints =>
{
    endpoints.MapBlazorHub();
    endpoints.MapFallbackToPage("/{param?}", "/_Host");
    endpoints.MapFallbackToPage("/_Host");
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900