简体   繁体   English

在具有不同根相对路径的代理后面运行ASP.NET MVC应用程序

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

I'm having trouble with paths in a ASP.NET MVC application that's running behind a proxy. 我在代理后面运行的ASP.NET MVC应用程序中遇到问题。

Our IIS Application root path is for example http://server/MyApp/ 我们的IIS应用程序根路径例如是http:// server / MyApp /

meaning that all urls using the application root ("~/",Url.Action("MyAction","MyController")) are resolved to "/MyApp" 意味着所有使用应用程序根目录的URL(“〜/”,Url.Action(“MyAction”,“MyController”))都被解析为“/ 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" 现在我们在代理服务器后面运行,转发所有请求,但要求您通过以下URL访问应用程序:“/ 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. 因为代理URL仅在客户端上可用,所以我想到创建一个带有路径前缀的cookie,并在服务器上的每个生成的URL之前插入它。

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)? 现在的问题是,代码中修改每个已解析/发送到客户端的URL(资源,控制器操作,图像等)的最佳位置是什么?

Every path in the application is resolved with the MVC methods (Url.Content, Url.Action etc). 应用程序中的每个路径都使用MVC方法(Url.Content,Url.Action等)解析。

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. 代理服务器大多数时间都会执行自己的URL转换,但在这种情况下,代理服务器会忽略以JSON格式传输的路径,并对它们进行处理。

My 'solution' for now is just not passing paths in JSON, but instead: 我现在的'解决方案'就是不在JSON中传递路径,而是:

  • using proper ID's and values in the JSON requests 在JSON请求中使用正确的ID和值
  • creating template in URL's in the HTML (which are resolved properly), 在HTML中的URL中创建模板(已正确解析),
  • replace the ID's and values in the URL template with the values from the JSON requests 使用JSON请求中的值替换URL模板中的ID和值

This method is actually a much 'cleaner' way IMO then passing the URL's. 这种方法实际上是一种非常“清洁”的方式IMO然后传递URL。

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. 您可以创建自己的asp.net mvc控制器工厂,根据请求的URL决定哪个控制器和操作将响应。 Check this url for a good blog post on how to do this - http://nayyeri.net/custom-controller-factory-in-asp-net-mvc . 请查看此URL以获取有关如何执行此操作的好文章 - http://nayyeri.net/custom-controller-factory-in-asp-net-mvc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM