简体   繁体   English

如何处理带有问号“?”的旧 aspx url 在不使用 IIS 的新 mvc 网站中

[英]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.

相关问题 在IIS中为mvc4网站/应用程序设置主页(无格式no.aspx) - setting homepage in IIS for mvc4 website /application (no forms no.aspx) Asp.net MVC路由为旧的aspx Url - Asp.net MVC routing for old aspx Url 如何在 URL MVC 路由上从问号 (?) 更改为斜线 (/)? - How do I change from question mark (?) to slash (/) on URL MVC Route? 如何将.aspx页面转换为PDF格式? 没有使用网站的网址 - How to convert .aspx page to pdf? without using a url from the site 如何使用旧的 asp 站点 url 正确重定向到 MVC 路由? - How redirect to MVC routes using a old asp site url correctly? 如何在不添加问号的情况下从应用程序配置读取文件路径? - How to read filepath from app config without adding question mark? MVC 4 URL路由以吸收旧的旧URL并转发到新域 - MVC 4 URL routing to absorb old legacy urls and forward to new domain 带有查询字符串的.aspx网址无法在没有.aspx的情况下重定向到url-我也想在新url上保留查询字符串 - .aspx url with query string is unable to redirect to url without .aspx - Also i want to retain the query string on new url 将aspx URL路由到MVC控制器 - Route an aspx url to MVC controller 如何在MVC中启动新的aspx页面时传递参数 - How to pass parameter in launching new aspx page in MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM