我如何获得Url.Action使用正确的端口号? [英] How do I get Url.Action to use the right port number?

查看:212
本文介绍了我如何获得Url.Action使用正确的端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC3建立一个网站,我使用剃刀语法创建的意见,这一切都在Azure上运行。

I'm creating a website using MVC3, I'm using the razor syntax to create the views and it's all running under azure.

目前我在蔚蓝的模拟器下本地运行。

Currently I'm running under the azure emulator locally.

我在URL中的观点:HTTP://本地主机:81 /布拉赫/富'。

I have a view at the url: 'http://localhost:81/Blah/Foo'.

在这个观点我想获得的URL,另一个动作。

In that view I want to get the Url for another action.

要做到这一点,我用:Url.Action(SomeAction,SomeController,空,this.Request.Url.Scheme)

To achieve this I use: Url.Action("SomeAction", "SomeController", null, this.Request.Url.Scheme)

但是,由于负载平衡蔚蓝的仿真器请求的变化作出的端口号。

However because of the load balancing the azure emulator does the port number the request is made on changes.

即。而它的81端口上运行,请求可能来自端口82。

i.e. whilst it's running on port 81, the request might come from port 82.

这导致创建一个不正确的URL的http://本地主机:82 /布拉赫/酒吧',我得到一个400,坏的主机名误差

This leads to to create an incorrect url 'http://localhost:82/Blah/Bar' and I get a 400, bad hostname error.

继在这个职位的信息<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/9142db8d-0f85-47a2-91f7-418bb5a0c675/\">http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/9142db8d-0f85-47a2-91f7-418bb5a0c675/我发现我可以用HttpContext.Request.Headers得到正确的主机和端口号[主机。

Following the info in this post http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/9142db8d-0f85-47a2-91f7-418bb5a0c675/ I found that I could get the correct host and port number using HttpContext.Request.Headers["Host"].

但我只能传递一个主机名Url.Action,如果我尝试过的主机名和端口,然后它仍然附加它认为是正确的端口,这样我结束了本地主机:81:82

But I can only pass a host-name to Url.Action, if I try passing the host-name and port then it still appends what it thinks is the right port so I end up with localhost:81:82.

编辑:我发现有人用同样的问题。他们似乎已经聚集我有(除非他们已经包含了再现太)相同的信息,但他们没有一个有用的补丁,因为我不能手动指定端口号。

I found someone with the same problem. They seem to have gathered the same information I have (except they've included a reproduction too) but they don't have a useful fix as I can't specify the port number manually.

<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/87c729e8-094c-4578-b9d1-9c8ff7311577/\">http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/87c729e8-094c-4578-b9d1-9c8ff7311577/

我想一个固定会是让我自己Url.Action超载,让我指定端口。

I suppose one fix would be to make my own Url.Action overload that lets me specify the port.

推荐答案

如果你只是用Url.Action(动作,控制器),会发生什么?这应该只是产生一个相对URL,它应该工作。

What happens if you just use Url.Action("Action", "Controller")? That should just generate a relative URL, which should work.

(或者也许更好的问题是:你为什么不使用过载)

(Or perhaps a better question is: why aren't you using that overload?)

这篇关于我如何获得Url.Action使用正确的端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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