用Javascript可以隱藏超級連結的真真實位址:
在顯示下載連結的頁sample.aspx的前台合適地方加入以下代碼如下:
<a href="#" onclick="javascript:window.open('DownLoad.aspx?ID=11','newwin','width=350,height=510,scrollbars=0,toolbar=0,resizable=0')">開啟視窗</a>
通過DownLoad.aspx檔案讀取需下載的檔案資訊,在後台加入代碼:
try
{
string str = "select FileContent,FileType, FileName from fileinfo where id = " + base.Request.QueryString["id"];
SqlDataReader Dr = pubValue.DataRead(str);
string strfilePath = "file/" + base.User.Identity.Name;
string path = "";
if (Dr.Read())
{
string s = Dr["FileName"].ToString();
path = base.Server.MapPath(strfilePath + "/" + s);
if (File.Exists(path))
{
File.Delete(path);
}
FileStream stream = new FileStream(path, FileMode.Create);
stream.Write((byte[])Dr["FileContent"], 0, ((byte[])Dr["FileContent"]).Length);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine("");
writer.Flush();
writer.Close();
stream.Close();
base.Response.Write("<script>location.href='" + strfilePath + "/" + base.Server.UrlEncode(s).Replace("+", "%20") + "';</script>");
}
}
catch (Exception exception)
{
base.Response.Write(exception.Message);
}
當滑鼠打向開啟視窗時,出現的連結資訊是#,而不是下載檔案的連結地址,從而達到隱藏真實的超級連結地址的效果!