如何使用MVC路由处理IIS子应用程序? [英] How to deal with IIS sub applications using MVC routing?
问题描述
我有一个MVC应用程序,该应用程序已移到wwwroot的子文件夹中,并且该子文件夹已通过IIS成为应用程序.因此,在进入我的登录页面的网址之前,是这样的:
I have an MVC application that has been moved to a sub folder in the wwwroot, and this sub folder has been made an application via IIS. So whereas before the url to my login page would look like this:
www.mydomain.com/login
现在看起来像这样:
www.mydomain.com/application/login
该应用程序运行正常,似乎没有影响我的应用程序中的路由或任何链接.但是,这会在我引用图像src的过程中引起问题,如下所示:
The application works fine, it doesn't seem to have affected the routing or any of the links in my application. However, it is causing problems where I am referencing image src's like so:
<img src="/content/images/myimage.png"/>
正在尝试从网址 www.mydomain.com/content/images/myimage.png 中检索图像,显然返回了404.
As it is attempting to retrieve the image from the url www.mydomain.com/content/images/myimage.png which obviously returns a 404.
在我的global.asax文件中,我仅使用默认路由,我已尝试将其修改为将子文件夹作为url的一部分:
In my global.asax file I am only using the default route, which I have attempted to modify to account for the subfolder as part of the url:
routes.MapRoute("Default",
"application/{controller}/{action}/{id}",
new { controller = "dashboard", action = "index", id = UrlParameter.Optional });
但是,现在当我尝试转到根URL www.mydomain.com/application 时,我只得到一个目录清单!如果我尝试直接进入控制器,即 www.mydomain.com/application/dashboard ,我会收到404!
However, now when I attempt to go to the root url www.mydomain.com/application I just get a directory listing! And if I try to go directly to controller i.e www.mydomain.com/application/dashboard I get a 404!
有人知道如何通过MVC路由处理这种情况吗?
Anyone got any idea how to deal with this situation via MVC routing?
推荐答案
- 您不需要更改路由.从入口点到您的应用程序都可以使用.
- 使用@ Url.Content(〜/content/images/myimage.png").
希望这会有所帮助.
这篇关于如何使用MVC路由处理IIS子应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!