How to deal with IIS sub applications using MVC ro

2019-07-24 17:23发布

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

It now looks like this:

www.mydomain.com/application/login

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"/>

As it is attempting to retrieve the image from the url www.mydomain.com/content/images/myimage.png which obviously returns a 404.

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 });

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!

Anyone got any idea how to deal with this situation via MVC routing?

2条回答
一纸荒年 Trace。
2楼-- · 2019-07-24 18:11

Try this one...

routes.MapRoute("Application",
                "application/{controller}/{action}/{id}",
                new { controller = "dashboard", action = "index", id = UrlParameter.Optional });

routes.MapRoute("Default",
                "{controller}/{action}/{id}",
                new { controller = "dashboard", action = "index", id = UrlParameter.Optional });
查看更多
小情绪 Triste *
3楼-- · 2019-07-24 18:12
  1. You don't need to change your routing. It works from entry point to your app.
  2. Use @Url.Content("~/content/images/myimage.png").

Hope this will help.

查看更多
登录 后发表回答