Running ASP.NET MVC application behind a proxy with different root relative path

吃可爱长大的小学妹 提交于 2019-12-22 08:05:51

问题


I'm having trouble with paths in a ASP.NET MVC application that's running behind a proxy.

Our IIS Application root path is for example http://server/MyApp/

meaning that all urls using the application root ("~/",Url.Action("MyAction","MyController")) are resolved to "/MyApp"

Now we're running behind a proxy server that forwards all requests, but requires you to access the application through a URL like this: "/Secury/Proxy/RubbishUrl/MyApp"

Because the proxy url is only available on the client, I thought of creating a cookie with the path prefix, and insert this before each generated URL on the server.

Now the question is, what's the best location in code to modify each URL that's resolved/sent to the client (to resources, controller actions, images etc)?

Every path in the application is resolved with the MVC methods (Url.Content, Url.Action etc).

Update: Not actively looking for an answer anymore (though still interested in a proper solution)

Most of the time Proxies do their own URL translation, however in this case the proxy server is ignoring paths that are transfered in JSON, and they are processed.

My 'solution' for now is just not passing paths in JSON, but instead:

  • using proper ID's and values in the JSON requests
  • creating template in URL's in the HTML (which are resolved properly),
  • replace the ID's and values in the URL template with the values from the JSON requests

This method is actually a much 'cleaner' way IMO then passing the URL's.


回答1:


You can create your own asp.net mvc controller factory where to decide which controller and action will serve the response based on the requested url. Check this url for a good blog post on how to do this - http://nayyeri.net/custom-controller-factory-in-asp-net-mvc.



来源:https://stackoverflow.com/questions/2591490/running-asp-net-mvc-application-behind-a-proxy-with-different-root-relative-path

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