我有一个客户端正在从 PHP 系统转换为 .NET 系统。其中一项要求是某些以“.php”结尾的旧系统 URL 在新的 .NET 环境中仍然可以访问。
本质上,我需要将任意字符串路径映射到特定的 Controller /操作。
谁能告诉我 ASP.NET Core 2.0 中推荐的、性能最高的方法是什么来处理这种情况?自定义中间件?引入一个Web.Config? Controller 中的操作属性?
有什么我应该注意的“陷阱”吗?
该网站托管在 Azure 中(如果这有区别的话)。
提前致谢!
最佳答案
Can anyone tell me what the recommended and most performant approach is in ASP.NET Core 2.0 to handle this scenario? Custom middleware? Introduce a Web.Config? Action attributes in the controller?
我认为您可以利用 URL Rewrite并阅读相关教程。我刚刚检查了它并通过 Azure App Service Editor 在我的 azure web 应用程序下添加了 URL 重写规则如下:
测试:
另外,您还可以在代码中编写URL重写规则,具体可以引用URL Rewriting Middleware in ASP.NET Core .
关于Azure 中的 ASP.NET Core 2.0 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761605/