[英]How to handle old aspx url with question mark '?' in new mvc website without using IIS
I have moved my pages of my website from aspx to mvc.我已将我的网站页面从 aspx 移动到 mvc。 I already have my old links in social media.我已经在社交媒体上有了我的旧链接。 After my mvc changes are published, my old URLs stop working, which is exactly the problem.在我的 mvc 更改发布后,我的旧 URL 停止工作,这正是问题所在。
Im using plesk and this edition does not have any settings to redirect URLs.我正在使用 plesk,这个版本没有任何重定向 URL 的设置。 So I dont think i can make use of redirection in IIS所以我认为我不能在 IIS 中使用重定向
My old URLs: https://www.abc123.com/movie?123我的旧网址: https://www.abc123.com/movie?123
My new URLs: https://www.abc123.com/title/123我的新网址: https://www.abc123.com/title/123
I have workaround with in MVC to handle aspx URL if my old url has proper query string like https://www.abc123.com/movie?id=123如果我的旧 url 具有正确的查询字符串,例如https://www.abc123?
[Route("movie")]
[Route("Title/{id}")]
public ActionResult Index(int id)
{
}
But this is not working with URL https://www.abc123.com/movie?123 as question mark (?) cannot be used in Route configs.但这不适用于 URL https://www.abc123.com/movie?123 ,因为问号 (?) 不能在路由配置中使用。
Kindly help me to handle this problem of mine.请帮助我处理我的这个问题。
Here is how I solved my problem:这是我解决问题的方法:
In controller of title I added below code,在标题的 controller 中,我添加了以下代码,
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (((HttpRequestWrapper)Request).CurrentExecutionFilePath.ToLower() != "/movie") {return; }
var id = Request.QueryString[null];
int titleid;
if (!int.TryParse(id, out titleid)) return;
Response.RedirectPermanent("~/title/" + titleid);
}
Thanks to AA感谢 AA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.