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

I am having problems with paths in an ASP.NET MVC application running behind a proxy server.

Our root path is an IIS application, for example, http: // server / MyApp /

means that all URLs using the application root ("~ /", Url.Action ("MyAction", "MyController")) are allowed for "/ MyApp"

Now we are working behind a proxy server that forwards all requests, but requires you to access the application through a URL, for example: "/ Secury / Proxy / RubbishUrl / MyApp"

Since the proxy server URL is only available on the client, I thought about creating a cookie with a path prefix and pasting it before each generated URL on the server.

Now the question is, what is the best place in the code to change each URL that is allowed / sent to the client (resources, controller actions, images, etc.)?

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

Update: Not actively looking for an answer anymore (although still interested in the correct solution)

In most cases, Proxies performs its own translation of URLs; however, in this case, the proxy server ignores the paths that are passed to JSON and they are processed.

My "solution" at the moment is simply not passing the path to JSON, but instead:

  • using the correct id and values ​​in JSON requests
  • creating a template in the URL in HTML (which is correctly resolved),
  • replace id and values ​​in URL pattern with values ​​from JSON requests

This method is actually a much cleaner way when IMO passes URLs.

+3
source share
1 answer

You can create your own mpc controller mpc asp.net factory, where you can decide which controller and action will respond to the request based on the requested URL. Check out this URL for a good blog post on how to do this - http://nayyeri.net/custom-controller-factory-in-asp-net-mvc .

0
source

All Articles