我已经使用 IIS8 在我们的网络服务器上设置了一个站点。 URL 是 ABC.mycompany.com 的链接。当我访问 ABC.mycompany.com 时,出现未找到错误:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
如果我访问 ABC.mycompany.com/Home/InstrumentList,它会显示我想要开始的正确页面。我如何让它从这条路线开始?
在 Visual Studio 2013 中,我将 Home/InstrumentList 设置为开始操作,效果很好。我查看了几个引用默认页面和索引页面的示例,但我的应用程序没有任何这些。此外,还有对 .aspx 页面的引用,但我的应用程序中没有 .aspx 页面,只有 .cshtml View 和 .cs Controller 。我还看到了有关添加路由的内容,但我不确定将它们放在 global.asax.cs 中的何处(在 ApplicationStart 中?在它之外?在不同的方法中?只是单独?)。我也不知道要更改什么才能为我的工作(将索引更改为 InstrumentListing 或保留它)。到目前为止,没有什么对我有用。
这是我使用 global.asax.cs 的尝试之一,我尝试添加注册路由方法:
namespace GPC
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
"{controller}/{action}/{Filtre}",
new { controller = "Home", action = "Index", Filtre = UrlParameter.Optional });
}
}
}
以下是我使用过的一些网站,但没有一个对我有用:
http://weblog.west-wind.com/posts/2013/Aug/15/IIS-Default-Documents-vs-ASPNET-MVC-Routes
cannot set Default route for MVC project
http://weblogs.asp.net/imranbaloch/editing-routes-in-mvc
如果有人可以向我展示如何在用户访问 ABC.mycompany.com 时显示 ABC.mycompany.com/Home/InstrumentList,我将不胜感激。
最佳答案
我不确定,但是您的 RegisterRoutes
方法应该位于 RouteConfig
类中,默认情况下应该位于 MVC 项目的 App_Start
文件夹中。 正如我在您的问题中看到的那样,这不是位于 Global.asax.cs
中的 MvcApplication
类中的方法。
那么你应该只像这样更改 RegisterRoutes
方法来设置不同的默认 Controller 操作:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
"{controller}/{action}/{Filtre}",
new { controller = "Home", action = "InstrumentList", Filtre = UrlParameter.Optional });
}
关于asp.net-mvc - 在 IIS 8 上设置 MVC 站点的默认路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31433864/