![](/img/trans.png)
[英]setting homepage in IIS for mvc4 website /application (no forms no.aspx)
[英]How to handle old aspx url with question mark '?' in new mvc website without using IIS
我已將我的網站頁面從 aspx 移動到 mvc。 我已經在社交媒體上有了我的舊鏈接。 在我的 mvc 更改發布后,我的舊 URL 停止工作,這正是問題所在。
我正在使用 plesk,這個版本沒有任何重定向 URL 的設置。 所以我認為我不能在 IIS 中使用重定向
我的舊網址: https://www.abc123.com/movie?123
我的新網址: https://www.abc123.com/title/123
如果我的舊 url 具有正確的查詢字符串,例如https://www.abc123?
[Route("movie")]
[Route("Title/{id}")]
public ActionResult Index(int id)
{
}
但這不適用於 URL https://www.abc123.com/movie?123 ,因為問號 (?) 不能在路由配置中使用。
請幫助我處理我的這個問題。
這是我解決問題的方法:
在標題的 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);
}
感謝 AA
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.