如何在asp.net中设置移动网页中的图像

发布于 2024-10-31 05:55:55 字数 335 浏览 1 评论 0原文

我为我的一位客户创建了一个移动网站。我在我的开发服务器和实时服务器上创建了一个网站。当我在开发服务器上上传图像徽标并在移动设备上检查时,图像显示正常。但是,当我将相同的代码放在实时服务器上时,图像不会显示在移动设备上,而是显示在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挽袖吟 2024-11-07 05:55:56

您应该使用图像控件。只需将其从 Visual Studio 中的工具箱中拖出,然后在属性面板中设置图像即可:

<asp:Image ID="MyImage" runat="server" ImageUrl="~/image/logo.jpg" />

这样您就永远不必担心路径,因为 ASP.NET 将始终确保它正确选择图像的路径。

现在,如果您只使用 HTML,那么您的问题就非常简单。尝试删除第一个斜杠。那应该可以解决问题。

<img src="image/logo.jpg"/>

或者,如果您尝试将其添加为 div 中的背景:

<div style="background-image: url("image/logo.jpg");"></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:

<asp:Image ID="MyImage" runat="server" ImageUrl="~/image/logo.jpg" />

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.

<img src="image/logo.jpg"/>

Or if your trying to add it as background in a div:

<div style="background-image: url("image/logo.jpg");"></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.

温柔戏命师 2024-11-07 05:55:56

正如其他人指出的那样,问题在于图像目录的路径。我们假设图像目录位于应用程序的根目录中。前导 / 指的是您网站的根 URL。在服务器控件中使用 ~/ 将导致 ASP.NET 将其替换为您应用程序的根 URL。
以下是一些可能会澄清的示例:

www.example.com/someApp/image/logo.jpg

/image/logo.jpg = www.example.com/image/logo.jpg

损坏的链接。这是指应用程序外部的目录。如果它在您的开发服务器上运行,那么它的根目录下必须有一个图像目录。

image/logo.jpg = www.example.com/someApp/image/logo.jpg

只要链接位于应用程序的根目录中,此功能就可以工作。

~/image/logo.jpg = 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

/image/logo.jpg = www.example.com/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.

image/logo.jpg = www.example.com/someApp/image/logo.jpg

This will work as long as the link resides in the root of the app.

~/image/logo.jpg = www.example.com/someapp/image/logo.jpg

This will work regardless of where the link resides. But the control containing the link must be set to runat="server".

哽咽笑 2024-11-07 05:55:56

我认为您的 html 格式不适合移动设备。

将其放在 html 文件的开头:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

然后检查它是否正确显示。

另外,请使用另一部手机检查该网站,并记住旧文件可能已被您的 ISP 缓存。

PS:像这样使用图片标签是可以的:

<img alt="the image" src="/image/logo.jpg" />

PPS:您的图片标签是否正确关闭?它缺少一个“/”

测试一下:

<img src="/image/logo.jpg" />

I think your html is not well formatted for mobile.

Put this at beginning of your html file:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

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:

<img alt="the image" src="/image/logo.jpg" />

P.P.S: Is your image tag closed properly? It's missing a "/".

Test this:

<img src="/image/logo.jpg" />
花想c 2024-11-07 05:55:56

要解决该问题,请使用以下语法:

< img src="~/image/logo.jpg" alt="不要忘记 alt"
runat="服务器">

To resolve it, use the following syntax:

< img src="~/image/logo.jpg" alt="Don't forget the alt"
runat="server">

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文