Running ASP.NET MVC application behind a proxy wit

2019-05-04 20:33发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-04 20:51

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.

查看更多
登录 后发表回答