2011-06-22 52 views
0
ResponseHelper.Redirect("popup.aspx?file= "+ LogicLayer.ManualPath + _ddlPLCs.SelectedValue.ToString() + "\\" + _PLCRow[0][0].ToString() ,"_page", "menubar=0,width=100,height=100"); 

反斜槓字符忽略了第二頁發送查詢字符串時asp.net

if (Request.QueryString["file"] != null) 
     { 
      LogicLayer.viewManual(Request.QueryString["file"].ToString()); 
     } 

我發現,斜線(\)字符是從文件路徑

有什麼想法去掉? ??

+0

刪除斜槓字符:d:\\ folder1 \\ manuals \\ pdfs \\ file1.pdf >>變成d:folder1手冊pdfs file1.pdf –

+1

我不認爲反斜槓字符對HTTP URL有效。您可以將它們更改爲'%5C'。另外,你可能想嘗試'HttpServerUtility.UrlEncode'函數 – Dirk

回答

1

反斜線(\)在URL中是不可接受的。您必須將字符編碼爲%HEX值。在ASP.Net中有一種方法來編碼一個URL字符串,另一種方法來解碼字符串。

在查看:

ResponseHelper.Redirect("popup.aspx?file= "+ System.Web.HttpUtility.UrlEncode(LogicLayer.ManualPath + _ddlPLCs.SelectedValue.ToString() + "\\" + _PLCRow[0][0].ToString()) ,"_page", "menubar=0,width=100,height=100"); 

後面的代碼:

if (Request.QueryString["file"] != null) 
{ 
    LogicLayer.viewManual(HttpServerUtility.UrlDecode(Request.QueryString["file"].ToString())); 
} 

Here's a similar question