我想重写网址
http://localhost:56713/Home/UserDetails?Code=223322
和
http://localhost:56713/223322
我在 StartUp.cs 中写了下面的内容,但它不起作用
var rewrite = new RewriteOptions()
.AddRewrite(@"{$1}", "Home/UserDetails?Code={$1}",true);
最佳答案
您需要在 AddRewrite 函数的第一个参数上使用正则表达式。
var rewrite = new RewriteOptions().AddRewrite(
@"^Home/UserDetails?Code=(.*)", // RegEx to match Route
"Home/{$1}", // URL to rewrite route
skipRemainingRules: true // Should skip other rules
);
此链接可能有助于提供更多示例
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?tabs=aspnetcore2x
关于c# - 在asp.net core 2.0中重写url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49405470/