简体   繁体   English

IIS提供本地URI而不是服务器名称

[英]IIS gives localhost URI instead of server name

IIS7 serving .Net web application (simple database site). IIS7服务.Net Web应用程序(简单数据库站点)。

I have a weird issue where the backgroundimage(URL) property of a element will be served as "http:\\localhost" instead of "http:\\servername". 我有一个奇怪的问题,其中元素的backgroundimage(URL)属性将用作“ http:\\ localhost”而不是“ http:\\ servername”。 This is a problem because when a user connects to my site, "localhost" would be their workstation, not the IIS server. 这是一个问题,因为当用户连接到我的站点时,“ localhost”将是其工作站,而不是IIS服务器。 So the image (in this case a button) is blank. 因此图像(在这种情况下为按钮)为空白。

The issue is intermittent, recycling the application pool seems to fix the issue for a time and then it comes back. 该问题是间歇性的,回收应用程序池似乎可以解决该问题一段时间,然后又回来。 IIS server also runs a SQL instance which eats ~28/36GB RAM. IIS服务器还运行一个SQL实例,占用了约28 / 36GB RAM。

Anyone ever seen anything like this? 有人看过这样的东西吗?

In order to fix this you need to search for all locations where "http:\\localhost" is hardcoded in your web app and replace it with a dynamic path. 为了解决此问题,您需要搜索Web应用程序中将“ http:\\ localhost”硬编码的所有位置,并将其替换为动态路径。 Even though localhost can work in your code if it is relative to the server, there are times when it will not work, such as in a link. 即使localhost相对于服务器而言也可以在您的代码中工作,但有时它仍然无法工作,例如在链接中。 You should get in the habit of never hardcoding your urls. 您应该养成永不对网址进行硬编码的习惯。

If you are using MVC - 如果您使用的是MVC-

value = Url.Content("~/Images/MyImage.png");

If you are using Forms - 如果您使用的是表格-

value = ResolveUrl("~/") + "Images/MyImage.png"

Or relative pathing - 或相对路径-

value = "~/Images/MyImage.png"

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

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