例如,传统的 URL 如下所示:
www.example.com?productID=123
我希望它看起来像
www.example.com/product/1234
我必须使用 MVC 来完成这个吗?
例如,传统的 URL 如下所示:
www.example.com?productID=123
我希望它看起来像
www.example.com/product/1234
我必须使用 MVC 来完成这个吗?
您不必为了漂亮的 URL 将整个应用程序转换为 MVC。
您可以使用urlrewriter轻松实现它。
web.config 中的类似内容 -
<rewriter>
<rewrite url="~/Product/(\d+)" to="~/default.aspx?productID=$1"/>
</rewriter>
注意:我没有测试上面的代码。我希望你能明白。
如果您的应用程序使用 .Net 4.5,您可能还想查看 ASP.Net 的 URL 路由。