c# - Why are backward slashes removed from querystring - ASP.NET & Javascript -


I am trying to generate a URL in which the UNC path is included as a query string variable. The URL will open in a pop up window when an ASP.NET button control is clicked by the user. When the button clicks, then PDS slash is removed from the UNC path, which causes the page to break.

The button is presented correctly in the page source file with all the backward slashes.

Is there any way to stop this?

Here is my source code:

Back code:

  string unc = @ "\\ myserver \ MyFolder \ myfile.txt"; String url = string.format ("http://www.mysite.com/page.aspx?a={0}", anak); MyButton.Attributes.Add ("OnClick", @ "Javascript: Flowerpot ('" + url + @ "')");  

ASPX page

  & lt; Script language = "javascript" type = "text \ javascript" & gt; Function FullPop (Neural) {Win = Window.Open (Neural, "Monitor", "Fullscreen = 0, Toolbar = 1, Location = 1, Directory = 1, Status = 1, MenuBur = 1, Scrollbar = 1, resizable = 1 , Width = 800, height = 600, top = 50, left = 50 "); Win.focus (); } & Lt; / Script & gt; & Lt; ASP: Button ID = "MyButton" runat = "server" cssclass = "mycss" text = "see actual target" />  

update

server. URLNX does not work. Based on Daniel Lev's answer, I have developed the following solution:

  Protected Zero Page_load (Object Sender, EventAgds E) {string unc = @ "\\ myserver \ myfolder \ myfile.txt "; String url = string.format ("http://www.mysite.com/page.aspx?a={0}", anak); MyButton.Attributes.Add ("OnClick", @ "Javascript: FullPop ('" + this.EscapeforJavaScript (url) + @ "')"); } Private string escape JavaWask (string url) {return url.Replace (@ "\", @ "\\"); } The url URL is encoded to the URL that you entered in the URL:  

  string url = "http://www.mysite.com/page.aspx?a=" + Server.UrlEncode (unc);  

Editing: To insert the URL safely in the JavaScript code, you also need to encode a string string for the string:

  Change MyButton ("'", @ "\'") + @ "')" Change "(" "," OnClick ", @" FullPop (' + url.Replace (@ "\", @ "\\ "); Javascript: Protocol is used only when JavaScript is used as a href for a link, not when you type code in an event such as onclickThe Alte.) 


Comments