如何在ASP.Net MVC中摆脱Home?

时间:2022-08-01 07:32:09

I know this site is written using ASP.Net MVC and I do not see "/Home" in the url. This proves to me that it can be done. What special route and do I need?

我知道这个网站是用ASP.Net MVC编写的,我在网址中看不到“/ Home”。这向我证明它可以做到。我需要什么特殊路线?

6 个解决方案

#1


17  

Just change "Home" to an empty string.

只需将“Home”更改为空字符串即可。

routes.MapRoute(
    "Home",
    "",
    new { action = Index, controller = Home }
);

#2


8  

If you're running on IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1. For more details check out:

如果您在IIS 7上运行,则只需删除ASP.NET MVC附带的Default.aspx文件(假设您在预览版3或更高版本上运行)。由于在.NET 3.5 SP1中修复了Cassini的问题,因此需要该文件。有关详细信息,请查看:

http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx and http://haacked.com/archive/2008/05/12/sp1-beta-and-its-effect-on-mvc.aspx

http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx和http://haacked.com/archive/2008/05/12/sp1-beta-and-its-效应上mvc.aspx

#3


6  

I actually like having all of my home controller methods to be at the root of the site. Like this: /about, /contact, etc. I guess I'm picky. I use a simple route constraint to do it. Here is my blog post with a code sample.

我实际上喜欢让我所有的家庭控制器方法都在网站的根目录。像这样:/ about,/ contact等等。我想我很挑剔。我使用一个简单的路由约束来做到这一点。这是我的博客文章,带有代码示例。

#4


1  

I'd add

我补充一下

routes.MapRoute("NoIndex", "{action}", new { controller = "Home", action = "Index" });

in RouteConfig.cs

在RouteConfig.cs中

#5


0  

This is what I did to get rid of Home. It will treat all routes with only one specifier as Home/Action and any with two as Controller/Action. The downside is now controller has to have an explicit index (/Controller != /Controller/Index), but it might help you or others.

这就是我摆脱Home所做的。它将只使用一个说明符作为Home / Action处理所有路由,将任何两个说明符作为Controller / Action处理。缺点是现在控制器必须有一个显式索引(/ Controller!= / Controller / Index),但它可能对你或其他人有所帮助。

routes.MapRoute(
    "Default",
    "{action}",
    new { controller = "Home", action = "Index" }
);

routes.MapRoute(
    "Actions",
    "{controller}/{action}",
    new { }
);

#6


-2  

In IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1.

在IIS 7中,您只需删除ASP.NET MVC附带的Default.aspx文件(假设您在Preview 3或更高版本上运行)。由于在.NET 3.5 SP1中修复了Cassini的问题,因此需要该文件。

For more details check out:

有关详细信息,请查看:

Upcoming Changes In Routing and .NET 3.5 SP1 Beta and Its Effect on MVC

路由和.NET 3.5 SP1 Beta即将发生的变化及其对MVC的影响

#1


17  

Just change "Home" to an empty string.

只需将“Home”更改为空字符串即可。

routes.MapRoute(
    "Home",
    "",
    new { action = Index, controller = Home }
);

#2


8  

If you're running on IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1. For more details check out:

如果您在IIS 7上运行,则只需删除ASP.NET MVC附带的Default.aspx文件(假设您在预览版3或更高版本上运行)。由于在.NET 3.5 SP1中修复了Cassini的问题,因此需要该文件。有关详细信息,请查看:

http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx and http://haacked.com/archive/2008/05/12/sp1-beta-and-its-effect-on-mvc.aspx

http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx和http://haacked.com/archive/2008/05/12/sp1-beta-and-its-效应上mvc.aspx

#3


6  

I actually like having all of my home controller methods to be at the root of the site. Like this: /about, /contact, etc. I guess I'm picky. I use a simple route constraint to do it. Here is my blog post with a code sample.

我实际上喜欢让我所有的家庭控制器方法都在网站的根目录。像这样:/ about,/ contact等等。我想我很挑剔。我使用一个简单的路由约束来做到这一点。这是我的博客文章,带有代码示例。

#4


1  

I'd add

我补充一下

routes.MapRoute("NoIndex", "{action}", new { controller = "Home", action = "Index" });

in RouteConfig.cs

在RouteConfig.cs中

#5


0  

This is what I did to get rid of Home. It will treat all routes with only one specifier as Home/Action and any with two as Controller/Action. The downside is now controller has to have an explicit index (/Controller != /Controller/Index), but it might help you or others.

这就是我摆脱Home所做的。它将只使用一个说明符作为Home / Action处理所有路由,将任何两个说明符作为Controller / Action处理。缺点是现在控制器必须有一个显式索引(/ Controller!= / Controller / Index),但它可能对你或其他人有所帮助。

routes.MapRoute(
    "Default",
    "{action}",
    new { controller = "Home", action = "Index" }
);

routes.MapRoute(
    "Actions",
    "{controller}/{action}",
    new { }
);

#6


-2  

In IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1.

在IIS 7中,您只需删除ASP.NET MVC附带的Default.aspx文件(假设您在Preview 3或更高版本上运行)。由于在.NET 3.5 SP1中修复了Cassini的问题,因此需要该文件。

For more details check out:

有关详细信息,请查看:

Upcoming Changes In Routing and .NET 3.5 SP1 Beta and Its Effect on MVC

路由和.NET 3.5 SP1 Beta即将发生的变化及其对MVC的影响