How to deal with IIS sub applications using MVC routing?

为君一笑 提交于 2020-01-05 03:28:41

问题


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?


回答1:


  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.




回答2:


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


来源:https://stackoverflow.com/questions/10330491/how-to-deal-with-iis-sub-applications-using-mvc-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!