【问题标题】:How to handle old aspx url with question mark '?' in new mvc website without using IIS如何处理带有问号“?”的旧 aspx url在不使用 IIS 的新 mvc 网站中
【发布时间】:2019-11-03 06:31:56
【问题描述】:

我已将我的网站页面从 aspx 移至 mvc。 我已经在社交媒体上有了我的旧链接。 在我的 mvc 更改发布后,我的旧 URL 停止工作,这正是问题所在。

我正在使用 plesk,并且此版本没有任何重定向 URL 的设置。所以我不认为我可以在 IIS 中使用重定向

我的旧网址:https://www.abc123.com/movie?123

我的新网址:https://www.abc123.com/title/123

如果我的旧网址具有正确的查询字符串,例如https://www.abc123.com/movie?id=123,我可以在 MVC 中使用解决方法来处理 aspx URL

        [Route("movie")]
        [Route("Title/{id}")]
        public ActionResult Index(int id)
        {
        }

但这不适用于 URL https://www.abc123.com/movie?123,因为问号 (?) 不能在路由配置中使用。

请帮我解决我的这个问题。

【问题讨论】:

标签: c# asp.net-mvc redirect


【解决方案1】:

这是我解决问题的方法:

在标题控制器中我添加了下面的代码,

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);
        }

感谢 AA

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多