asp.net mvc、asp.net url重写 Url Rewrite

最近在做一个cms手机网站,由于内容不是很多,很快做完了。空闲的时间考虑seo,想把url全部写成静态的。在查资料的时候,发现 UrlRewrite.Net这个组件非常的不错,尝试了下结果达到了理想的效果。

1、通过nuget安装该类库;

2、注册为后缀html的路由;

3、web.config配置;

  <!--在 configuration 节点下配置-->
  <configSections>
    <section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter" />
  </configSections>

<!--在 system.webServer 节点下配置--> <modules runAllManagedModulesForAllRequests="true"> <remove name="UrlRoutingModule" /> <add name="UrlRoutingModule" type="UrlRewrite.RewriteModule, UrlRewrite" preCondition="managedHandler" /> </modules>

4、生成url链接的时候添加上后缀,如果使用,如果是使用 @Html.ActionLink("主页", "Index", "Home") 这方式生成,会自动生成带后缀.html;

5、测试访问;

到此就可以了,这样比较有利于seo;

猜你喜欢

转载自www.cnblogs.com/changsen-wang/p/12575693.html
今日推荐