运行背后不同的根目录的相对路径代理ASP.NET MVC应用程序 [英] Running ASP.NET MVC application behind a proxy with different root relative path

查看:125
本文介绍了运行背后不同的根目录的相对路径代理ASP.NET MVC应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与一个ASP.NET MVC应用程序的运行背后的代理路径的麻烦。

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

我们的IIS应用程序的根路径,例如的http://服务器/ MyApp的/

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

这意味着使用应用程序根目录的所有URL(〜/,Url.Action(MyAction,myController的))解析成/ MyApp的

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

现在我们落后转发所有请求,但要求你通过这样的URL访问应用程序的代理服务器上运行:
/ Secury /代理/ RubbishUrl / 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仅仅是客户机上使用,我想创建一个与路径preFIX一个cookie,而服务器上的每个生成的URL之前插入此。

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.

现在的问题是,什么是在code的最佳位置修改发送到客户端(资源,控制器动作,图像等)这就是解决每一个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)?

在应用程序中的每个路径与方法MVC(​​Url.Content,Url.Action等)。解决

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)

大多数时候代理做自己的URL转换,但是在这种情况下,代理服务器被忽视了在JSON转移路径,而且它们被处理。

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.

我的'解决方案',现在只是没有通过的路径在JSON,而是:

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


  • 使用正确的ID和值在JSON请求

  • 在HTML创造URL的模板(这是妥善解决),

  • 更换ID的和值与值的网址模板从JSON请求

这方法其实是一个更清洁的方式IMO然后通过URL的。

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

推荐答案

您可以创建自己的asp.net的MVC控制器工厂,以决定哪个控制器和行动将成为基于请求的URL的响应。检查下列网址,如何做一个很好的博客文章 - 的http:/ /nayyeri.net/custom-controller-factory-in-asp-net-mvc

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.

这篇关于运行背后不同的根目录的相对路径代理ASP.NET MVC应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆