【发布时间】:2020-05-09 14:53:06
【问题描述】:
在 ASP.NET Core 中处理应用程序时我在尝试重写单个 url 时遇到问题,例如: https://localhost:44318/Details?content=My-url-to-rewrite&id=221 进入 https://localhost:44318/mypage
我在 Startup.cs 的 Configure() 方法开头使用的代码如下:
app.UseRewriter(new RewriteOptions()
.AddRewrite(@"^Details?content=My-url-to-rewrite&id=221", "/mypage", skipRemainingRules: true));
奇怪的是,如果我尝试在没有查询字符串的情况下重写 url,如下所示,它可以工作
app.UseRewriter(new RewriteOptions()
.AddRewrite(@"^Details", "/mypage", skipRemainingRules: true));
甚至添加问号来附加它的查询字符串,如下所示
app.UseRewriter(new RewriteOptions()
.AddRewrite(@"^Details?", "/mypage", skipRemainingRules: true));
但是,只要我在问号后添加一个字符,url 就不会被重写,并且页面会像往常一样被链接,没有任何错误。
有什么想法吗?
提前致谢。
【问题讨论】:
标签: asp.net-core url-rewriting