如何在asp.net中设置移动网页中的图像
我为我的一位客户创建了一个移动网站。我在我的开发服务器和实时服务器上创建了一个网站。当我在开发服务器上上传图像徽标并在移动设备上检查时,图像显示正常。但是,当我将相同的代码放在实时服务器上时,图像不会显示在移动设备上,而是显示在我的 PC 上。
我只是使用简单的 HTML:
我什至尝试了下面的代码,在图像 URL 中使用或不使用引号。
I have a mobile website created for one of my clients. I created a site on my development server and live server. When I upload an image logo on the development server and check it on mobile, the image is displayed properly. But when I put the same code on my live server, the image is not shown on mobile but is shown on my PC.
I am just using simple HTML:
<img src="/image/logo.jpg">
I even tried the code below with and without quotes in the image URL.
<div style="background-image: url(/image/logo.jpg)" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用图像控件。只需将其从 Visual Studio 中的工具箱中拖出,然后在属性面板中设置图像即可:
这样您就永远不必担心路径,因为 ASP.NET 将始终确保它正确选择图像的路径。
现在,如果您只使用 HTML,那么您的问题就非常简单。尝试删除第一个斜杠。那应该可以解决问题。
或者,如果您尝试将其添加为 div 中的背景:
请直接从 MSDN 查看此页面,该页面解释了链接到网站中图像的几乎所有可能的方式:
作为参考, microsoft.com/en-us/library/ms178116%28l=en-us,v=VS.90%29.aspx" rel="nofollow noreferrer">ASP.NET 网站路径
如果是这样,请告诉我有帮助。
You should use an image control. Just drag it from the toolbox in Visual Studio and set the image in the properties panel:
Then you'll never have to worry about paths because ASP.NET will always make sure it correctly chooses the path to your image.
Now if your only using HTML, your problem is super simple. Try removing the first slash. That should do the trick.
Or if your trying to add it as background in a div:
And for your reference check out this page directly from MSDN that explains pretty much every possible way to link to images in a website:
ASP.NET Web Site Paths
Let me know if this helps.
正如其他人指出的那样,问题在于图像目录的路径。我们假设图像目录位于应用程序的根目录中。前导 / 指的是您网站的根 URL。在服务器控件中使用 ~/ 将导致 ASP.NET 将其替换为您应用程序的根 URL。
以下是一些可能会澄清的示例:
www.example.com/someApp/image/logo.jpg
损坏的链接。这是指应用程序外部的目录。如果它在您的开发服务器上运行,那么它的根目录下必须有一个图像目录。
只要链接位于应用程序的根目录中,此功能就可以工作。
无论链接位于何处,这都将起作用。但包含链接的控件必须设置为 runat="server"。
As others have pointed out the problem is with the path to the image directory. We're assuming that the image directory resides in the root of your app. The leading / refers to the root URL of your site. Using ~/ in server controls will cause asp.net to replace this with the root URL of you app.
Here are some examples that might clarify:
www.example.com/someApp/image/logo.jpg
Broken link. This refers to a directory outside of your app. If it worked on your development server then it must have an image directory at it's root.
This will work as long as the link resides in the root of the app.
This will work regardless of where the link resides. But the control containing the link must be set to runat="server".
我认为您的 html 格式不适合移动设备。
将其放在 html 文件的开头:
然后检查它是否正确显示。
另外,请使用另一部手机检查该网站,并记住旧文件可能已被您的 ISP 缓存。
PS:像这样使用图片标签是可以的:
PPS:您的图片标签是否正确关闭?它缺少一个“/”。
测试一下:
I think your html is not well formatted for mobile.
Put this at beginning of your html file:
And then check if it's displayed properly.
Also check the web site with another mobile phone and remember that old files may be cached by your ISP.
P.S: Using image tag like this is OK:
P.P.S: Is your image tag closed properly? It's missing a "/".
Test this:
要解决该问题,请使用以下语法:
To resolve it, use the following syntax: