ASP.NET MVC中的虚拟目录 [英] ASP.NET MVC in a virtual directory
问题描述
我在我的Global.asax.cs以下
I have the following in my Global.asax.cs
routes.MapRoute(
"Arrival",
"{partnerID}",
new { controller = "Search", action = "Index", partnerID="1000" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
我SearchController看起来像这样
My SearchController looks like this
public class SearchController : Controller
{
// Display search results
public ActionResult Index(int partnerID)
{
ViewData["partnerID"] = partnerID;
return View();
}
}
和Index.aspx的只显示计算机[PARTNERID]的时刻。
and Index.aspx simply shows ViewData["partnerID"] at the moment.
我在IIS设置在Windows XP虚拟目录名为Test。
I have a virtual directory set up in IIS on Windows XP called Test.
如果我点我在 HTTP浏览器://本地主机/测试/ 然后我得到1000显示预期。但是,如果我尝试的http://本地主机/测试/ 1000 我收到找不到错误的页面。任何想法?
If I point my browser at http://localhost/Test/ then I get 1000 displayed as expected. However, if I try http://localhost/Test/1000 I get a page not found error. Any ideas?
是否有在虚拟目录中运行MVC任何特殊注意事项?
Are there any special considerations for running MVC in a virtual directory?
推荐答案
IIS 5.1间$ P $其中pts您的网址,以便其寻找一个名为test的文件夹下的文件夹1000。为什么会这样?
IIS 5.1 interprets your url such that its looking for a folder named 1000 under the folder named Test. Why is that so?
这是因为IIS 6只
ASP.NET调用它看到一个时
文件扩展名中是这样的网址
映射到ASPNET_ISAPI.DLL(这是一个
C / C ++ ISAPI筛选器负责
调用ASP.NET)。由于路由是
.NET IHttpModule的所谓
UrlRoutingModule,它不会
调用,除非ASP.NET本身得到
调用,它只是发生在
ASPNET_ISAPI.DLL被调用,这
只有当有一个发生的.aspx
该URL。所以,没有的.aspx,无
UrlRoutingModule,因此404。
This happens because IIS 6 only invokes ASP.NET when it sees a "filename extension" in the URL that’s mapped to aspnet_isapi.dll (which is a C/C++ ISAPI filter responsible for invoking ASP.NET). Since routing is a .NET IHttpModule called UrlRoutingModule, it doesn’t get invoked unless ASP.NET itself gets invoked, which only happens when aspnet_isapi.dll gets invoked, which only happens when there’s a .aspx in the URL. So, no .aspx, no UrlRoutingModule, hence the 404.
最简单的解决方法是:
如果你不介意在有你的.aspx
网址,只要通过你的路由
配置,之前添加的.aspx
每个模式中的斜杠。对于
例如,使用
{}控制器的.aspx / {行动} / {ID}或
myapp.aspx / {控制器} / {行动} / {显示}。
不要把里面的.aspx的
花括号参数名称,或进入
默认值,因为它不是
真的控制器名称的一部分 -
它只是在URL中满足IIS。
If you don’t mind having .aspx in your URLs, just go through your routing config, adding .aspx before a forward-slash in each pattern. For example, use {controller}.aspx/{action}/{id} or myapp.aspx/{controller}/{action}/{id}. Don’t put .aspx inside the curly-bracket parameter names, or into the ‘default’ values, because it isn’t really part of the controller name - it’s just in the URL to satisfy IIS.
来源:的http://blog.$c$cville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
这篇关于ASP.NET MVC中的虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!