我與顯示來自服務器的Z文件的工作:/文件目錄。問題是,當PDF和JPEG/JPG文件在本地主機的Iframe內正確呈現時,當我使用IIS服務器IP名稱192.168.xxx.xxx:8081/Home.aspx時,它們不呈現。我也有一個下載按鈕,用戶可以在其中下載文件。 Iframe和下載按鈕指向相同的源,但Iframe不會正確返回/顯示文件。它只是顯示空白。PDF和JPEG文件不會在iframe中顯示,但可在本地主機
這裏是源URL的一個例子:\ 192.168.xxx.xxx \ Z $ \文件目錄\ PDF文件\ cyber.pdf。
哦,順便說一句,我也將它們映射到iFrame和動態下載按鈕。
protected string GetPath(TreeNode treenode)
{
string[] array = new string[100];
string path = string.Empty;
int depth = treenode.Depth;
TreeNode node = new TreeNode();
node = treenode;
array[0] = node.Value;
for (int i = 1; i <= depth; i++)
{
array[i] = node.Parent.Value;
node = node.Parent; ;
}
//path = "~/";
path = @"\\192.168.3.12\Z$\";
for (int i = depth; i >= 0; i--)
{
if (Path.GetExtension(array[i].ToString()) == string.Empty)
{
//path += array[i].ToString() + "/";
path += array[i].ToString() + @"\";
}
else
path += array[i].ToString();
}
return path;
}
protected void trvNews_SelectedNodeChanged(object sender, EventArgs e)
{
try
{
if (trvNews.SelectedNode.Expanded == true)
{
trvNews.SelectedNode.Collapse();
trvNews.SelectedNode.Selected = false;
}
else if(trvNews.SelectedNode.Expanded == false)
trvNews.SelectedNode.Expand();
if (trvNews.SelectedNode.ChildNodes.Count == 0)
{
if (Path.GetExtension(trvNews.SelectedNode.Text) == string.Empty)
{
hfPath.Value = GetPath(trvNews.SelectedNode);
//ListDirectory(trvNews, Server.MapPath(hfPath.Value), "NoChild");
ListDirectory(trvNews, hfPath.Value, "NoChild");
Session["Count"] = "Enabled";
}
else
{
string test2 = Path.GetFullPath(hfPath.Value);
string path = hfPath.Value + trvNews.SelectedNode.Text;
//site = "DocumentViewer.aspx?=" + Path.GetFileName(path);
string url = "DocumentViewer.aspx?=" + Path.GetFileName(path);
Session["Path"] = path;
//ClientScript.RegisterStartupScript(typeof(Page), "Sigma", "open_win()", true);
ScriptManager.RegisterClientScriptBlock(this, GetType(), "newpage", "open_win('" + url + "');", true);
Session["Count"] = "Enabled";
}
}
string test = Session["Count"].ToString();
if (Session["Count"].ToString() == "Enabled")
btnBack.Visible = true;
}
catch (Exception ex)
{
LogError(ex, "User");
}
}
這是第一頁中的代碼,因爲用戶單擊該文件以查看/下載它。下一頁是..
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
string path = Session["Path"].ToString();
int length = path.Length;
lblHead.Text = Path.GetFileName(path);
System.IO.FileInfo file = new System.IO.FileInfo(Session["Path"].ToString());
if (Path.GetExtension(path) == ".pdf")
{
pnlPdf.Visible = true;
if (Session["FromNews"] != null)
framePdf.Attributes["src"] = FormulatePathPDFNews(path);
else
{
framePdf.Attributes["src"] = "\\\\" + file.FullName;
}
}
else if (Path.GetExtension(path) == ".jpeg" || Path.GetExtension(path) == ".jpg")
{
pnlJpeg.Visible = true;
//imageJpeg.Attributes["src"] = FormulatePath(path);
imageJpeg.Attributes["src"] = file.FullName;
}
}
}
catch (Exception ex)
{
LogError(ex, "User");
}
}
的下載按鈕,這就是:
protected void btnDownload_Click(object sender, EventArgs e)
{
try
{
if (Path.GetExtension(Session["Path"].ToString()) != null)
{
System.IO.FileInfo file = new System.IO.FileInfo(Session["Path"].ToString());
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
Response.Write("This file does not exist.");
}
}
catch (Exception ex)
{
LogError(ex, "User");
}
}
他們正在努力在本地主機完全正常,但在IIS服務器時不顯示。有小費嗎?
是否IIS下運行的網站有權限的網絡目錄的帳戶和它的文件嗎? – Sethcran
如何在IIS中設置權限?我設定目錄被所有人看到只是爲了測試這個想法。但它仍然是一樣的。文件無法顯示。 –