MVC - 重写URL仅显示域 [英] MVC - Rewrite URL to display domain only

查看:106
本文介绍了MVC - 重写URL仅显示域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET 3.5框架使用MVC 1.0。我有谁希望URL的客户端显示为 www.example.com 而不是 www.example.com/ {控制器} / {行动} / {ID}

I am using MVC 1.0 in .NET 3.5 Framework. I have a client who would like the URL to be displayed as www.example.com instead of www.example.com/{controller}/{action}/{id}.


  1. ,该网站是在正在利用IIS 6托管服务器。

  2. 我没有到该服务器的直接连接。

考虑到这一点,可以这样做?

With that in mind, can this be done?

有人使用的ISAPI_Rewrite建议。我发现了几个例子,但没有实际正确地说明需要做什么。

Someone suggested using ISAPI_REWRITE. I've found a few examples but none that actually explain correctly what needs to be done.

另外,如果这个不能整个网站来完成。可它只是在主页上做了什么?

Alternatively, if this cannot be done throughout the site. Can it just be done on the Home page?

下面是我的路由的时刻:

Below is my routing at the moment:

public static void RegisterRoutes(RouteCollection routes)
{
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     // Catch all route
     routes.MapRoute(
     "Default", // Name
     "{lang}/{controller}" + System.Configuration.ConfigurationManager.AppSettings["extension"] + "/{action}/{*values}",  // URL - ["extension"] being .aspx for IIS 6
     new { lang = "EN", controller = "Content", action = "Index" } // Defaults);
 }

先谢谢了。

推荐答案

您应该写

public static void RegisterRoutes(RouteCollection routes)
{
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
         "HomeIndex", // Name
         "",
         new { lang = "EN", controller = "Home", action = "Index" } // Defaults);


     // Catch all route
     routes.MapRoute(
     "Default", // Name
     "{lang}/{controller}" + System.Configuration.ConfigurationManager.AppSettings["extension"] + "/{action}/{*values}",  // URL - ["extension"] being .aspx for IIS 6
     new { lang = "EN", controller = "Content", action = "Index" } // Defaults);
 }

这篇关于MVC - 重写URL仅显示域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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