将 www 链接路由到 .net mvc 中的非 www 链接 [英] Route www link to non-www link in .net mvc

查看:15
本文介绍了将 www 链接路由到 .net mvc 中的非 www 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET MVC 中内置的友好路由库似乎允许我们做这样的事情.

It seems with the built in friendly routing library in .NET MVC, it would allow us to do something like this.

如果不清楚我想要使用 .NET MVC 中的内置内容做什么,我希望使用 MVC 框架将以 www 开头的网址自动重定向到非 www 网址.

In case it's not obvious what I want to with the built in stuff in .NET MVC, I want to a url starting with www to be automatically redirected to a non-www url using the MVC framework.

推荐答案

有多种方法可以实现从 www 到非 www 的 301 重定向.我更喜欢在某些项目中将这种重定向逻辑保留在 ASP.NET 级别(即在我的应用程序中),但其他项目需要更好的性能,例如 IIS7 url 重写.

There are a number of ways to do the 301 redirect from the www to the not-www. I prefer to keep this redirection logic at the ASP.NET level (i.e. in my app) in some projects, but others require better performing things, like IIS7 url rewriting.

这是 在 ASP.NET 论坛上讨论,我选择使用每个控制器上的 WwwFilter.这对我有用,没有问题.

It was discussed on the ASP.NET forums and I chose to use a WwwFilter on each controller. This has worked for me, no issues.

这篇关于将 www 链接路由到 .net mvc 中的非 www 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆