【问题标题】:How to enable store virtual directory and Store controller in MVC4 application in Windows 2003 server如何在 Windows 2003 服务器的 MVC4 应用程序中启用存储虚拟目录和存储控制器
【发布时间】:2013-10-24 14:41:45
【问题描述】:

使用 IIS 的 Windows 2003 服务器中的 ASP.NET MVC4 应用程序在虚拟目录存储中并具有存储控制器,例如 url 可以是

http://mysite.com/store/Store/Details?product=C201S

这个应用程序也需要从 root 访问,因为

http://mysite.com/Store/Details?product=C201S

因为这个应用程序目录的副本已经创建并且默认的网络应用程序指向它。 但是http://mysite.com/Store/Details?product=C201S 返回错误

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: /Store/Details


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 

在 url 中不包含 Store 控制器的链接可以正常工作。 它看起来像商店应用程序和商店控制器名称冲突。如何解决这个问题?

global.asax.cs 包含默认路由:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    //http://haacked.com/archive/2010/02/12/asp-net-mvc-2-optional-url-parameters.aspx
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
}

【问题讨论】:

  • 通过设置一个虚拟目录并在其中放置一个 Web 应用程序,您的 Web 应用程序的根目录就是虚拟目录:http://my site.com/VIRTUAL_DIRECTORY/。所以没有碰撞。

标签: asp.net asp.net-mvc asp.net-mvc-4 iis asp.net-mvc-routing


【解决方案1】:

根据我的评论,要使两个 Url 都能正常工作,您应该将虚拟目录的父网站的主目录设置为与虚拟目录 this page 相同的目录。

【讨论】:

  • 默认网站中根目录的主目录设置为 c:\myapp\web\storepea,虚拟目录属性中商店虚拟目录的主目录设置为 c:\myapp\web\store。究竟应该改变什么?我更新了问题并添加了图片
  • @Andrus 您的默认网站的主目录应更改为c:\myapp\web\store。
猜你喜欢
  • 1970-01-01
  • 2019-01-02
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 2019-11-01
  • 2011-11-07
  • 1970-01-01
  • 2020-08-01
相关资源
最近更新 更多