我使用两个图像标记。在一个使用的路径是相对的,而另一个则是绝对的。没有显示绝对路径图像。下面是代码:为什么图像标签中的属性imageurl不能接受绝对路径?
Expt_Image2.aspx页:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Expt_Image2.aspx.cs" Inherits="Expt_Image2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image
ID="Image1"
runat="server"
ImageUrl="~/Image/Bluehills.jpg"
Height="100"
Width="100"/>
<asp:Image
ID="Image2"
runat="server"
ImageUrl="C:\Documents and Settings\Lovey\My Documents\Visual Studio 2008\WebSites\Expt-New\Image\Sunset.jpg"
Height="100"
Width="100"/>
</div>
</form>
</body>
</html>
Expt_Image2.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class Expt_Image2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] files = Directory.GetFiles(MapPath("~/Image/"));
Image im = new Image();
im.ImageUrl = files[1];
im.AlternateText = files[1];
form1.Controls.Add(im);
}
}
如果您检查呈现的HTML,它期望映像位于何处?这实际上是图像的位置吗? – Fishcake 2011-02-14 09:17:55
嗨主要点是安全,如果任何web应用程序被允许访问系统目录以外的允许的[从哪里运行应用程序的文件夹称为根〜],然后任何代码可以删除任何文件,服务器上的文件夹,你知道会有超过一个托管在您的服务器和服务器系统配置上的网站将不允许您访问〜及其子文件夹之外的任何内容。 – Learner 2011-02-14 12:47:08