IIS服务器中的PDF和JPEG文件不在Iframe中呈现,而是在localhost上工作
本文关键字:localhost 工作 Iframe PDF JPEG 文件 IIS 服务器 | 更新日期: 2023-09-27 18:24:15
我正在处理显示服务器Z:/File目录中的文件。问题是,虽然PDF和JPG/JPG文件在本地主机的Iframe中正确渲染,但当我使用IIS服务器IP名称192.168.xxx.xxx:8081/Home.aspx时,它们不会渲染。我还有一个下载按钮,用户可以在其中。。下载文件。Iframe和下载按钮指向同一个源,但Iframe没有正确返回/显示文件。它只是显示空白。
以下是源URL:''192.168.xxx.xxx''Z$''File Directory''PDF Files''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");
}
}
它们在localhost中工作得很好,但在IIS服务器中不显示。有什么建议吗?
大多数情况下,这表示找不到路径或文件夹需要权限。
该网站将在特定用户下运行(查看应用程序池中的标识),该用户将需要对文件夹的权限。