파일 이름을 저장하는 다음과 같은 템플릿 필드가있는 GridView가 있습니다. 사용자가 파일 이름을 클릭하면 window.open()을 호출하여 파일을 엽니 다. 내 질문은 window.open() 상대 경로를 전달할 수 있습니다. 전체 경로를 사용하면 오류가 발생합니다. 파일을 열 때 전체 경로를 사용할 수있는 방법이 있습니까? 감사.전체 경로로 파일을 여는 방법은 무엇입니까?
<asp:TemplateField HeaderText="FileName">
<ItemTemplate>
<asp:LinkButton ID="lnkFile" runat="server"
Text='<%# Eval("FileName")%>' OnClick="lnkFile_Click">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
추가 : 파일의 실제 위치는 web.config에 정의되어 있습니다.
다음 lnkFile_Click()을 작성했습니다. 이전 부분은 파일에 대한 새 창이 열리지 만 파일의 전체 경로를 전달할 수는 없습니다. 새로운 부분을 통해 파일을 열거 나 저장할 수 있습니다. 제 질문은 이것이 보안 문제를 일으키는 것입니까?
protected void lnkFile_Click(object sender, System.EventArgs e)
{
string fileName = ConfigurationSettings.AppSettings["SPRAttachmentLocation"] + "\\SPR" + sprID + "\\" + ((LinkButton)sender).Text;
if (!File.Exists(fileName))
{
Exception ex = new Exception("Could not find the file, please contact your administrator.");
Response.Write("<p align=\"center\"><br /><br /><br /><br />There has been an Error: <strong>" + ex.Message + "</strong></p>\n");
return;
}
새로운 기능 :
byte[] bts = System.IO.File.ReadAllBytes(fileName);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
올드 :
string newWindowUrl = "/SPR_Upload/SPR" + sprID + "/" + ((LinkButton)sender).Text;
string javaScript =
"<script type='text/javascript'>\n" +
"<!--\n" +
"window.open('" + newWindowUrl + "');\n" +
"// -->\n" +
"</script>\n";
Page.ClientScript.RegisterStartupScript(GetType(), "", javaScript);
}
어떤 오류가 발생 했습니까? – keyboardP
이 파일은 웹 사이트/응용 프로그램 폴더 아래에 있습니까? window.open()은 URL로 절대 주소를 지정할 수 있습니다. 상대적 또는 절대적입니다. 여기서 절대 값은 "HTTP", "HTTPS"등으로 시작합니다. – GalacticCowboy
파일의 실제 위치는 web.config에 정의되어 있습니다. 원격 컴퓨터의 웹 사이트/응용 프로그램 폴더 아래에있을 수 있습니다.그래서 당신은 window.open()을 사용할 수 없다는 것을 의미합니다. 사용할 수있는 다른 기능이 있습니까? – GLP