Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

asp.net - Rebuilt My .ASPX Website But How to Easily Redirect to .NET Core Pages [on Shared Hosting]?

I know this has been asked before but I haven't seen any simple explanations and I should also add I'm on shared hosting (Plesk). I don't see the URLRewriter utility installed on the server.

Anyway, I rebuilt my 2013 website that did use ASP.NET web forms (with .ASPX extensions). I'd like to be able to redirect my old pages to their new equivalents. i.e.

https://www.findaforum.net/diyfishkeepers-com.aspx

Should now point to:

https://www.findaforum.net/Forums/diyfishkeepers-com/

At the moment the .ASPX pages show this in a red box on a yellow screen:

XML Parsing Error: no element found Location: https://www.findaforum.net/diyfishkeepers-com.aspx Line Number 1, Column 1:

Where does this "come" from?

Incidentally, I'm looking for a quick and easy fix because I don't have too many external links pointing to my site's subpages, but it would be nicer for the user experience to fix it while Google works out I've changed my entire site.

question from:https://stackoverflow.com/questions/65841421/rebuilt-my-aspx-website-but-how-to-easily-redirect-to-net-core-pages-on-share

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This answer basically works:

How to redirect .ASPX pages to .NET Core Razor page

There's a good link to the URL rewriting regular expressions here: https://isitoktocode.com/post/introduction-to-url-rewriting-using-iis-url-rewrite-module-and-regular-expressions

This is what I've put in Startup.cs:

var options = new RewriteOptions()
.AddRedirect(@"ShowCategories.aspx", "/Home/Categories/")
.AddRedirect(@"Statistics.aspx", "/Home/TopForums/")
.AddRedirect(@"SubmitForum.aspx", "/Home/Submit/")
.AddRedirect(@"Help.aspx", "/Home/HelpAndFAQ/")
.AddRedirect(@"([0-9a-z-A-Z]+)(.aspx)", "/Forums/$1/");
        app.UseRewriter(options);

Note: Make sure you put the specific ones at the top, then the generic ones at the bottom.

I also had some URLs like https://www.findaforum.net/lpsg-com where 'lpsg-com' is a forum name. I added a URL to the home controller to take care of these...

[HttpGet]
[Route("{code}")]
public ActionResult Unknown(string code)
{
return RedirectToAction(code, "Forums");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...