在asp mvc中删除Localhost URL

时间:2012-01-06 11:14:46

标签: c# asp.net-mvc

尝试从外部网站正确显示图像时遇到问题但mvc约束链接并在所有内容的开头自动添加localhost:url,即使使用自定义路由也无法避免

例如我需要:www.google.com/finance/chart?q = NYSE:V& tlf = 12

但我得到了:http://localhost:3022/www.google.com/finance/chart?q=NYSE:V&tlf=12

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:6)

你的问题不是MVC;它是<a>标签的形成。你是这样做的:

<a href="www.google.com/finance/chart?q=NYSE:V&tlf=12">blah...</a>

你应该这样做:

<a href="http://www.google.com/finance/chart?q=NYSE:V&tlf=12">blah...</a>

如果不在开头包含协议,浏览器会假定您的链接是相对于当前网站的。它与MVC没有任何关系。

答案 1 :(得分:0)

如果您需要单独域上的链接,则需要添加http://

所以:

  

http://www.google.com/finance/chart?q=NYSE:V&tlf=12

应该工作!

为什么呢?如果没有http,则链接被视为相对链接,浏览器使用相对域 - &gt; localhost