从web.config获取URL

Avi*_*dra 4 javascript c# asp.net

我试图在配置文件中存储一个URL,但是当我从文件中检索URL时它不起作用

以下是我的代码

在web.config中,我有

 <add key="URL" value="/NG/Viewer/ViewerSummary.aspx"/>
Run Code Online (Sandbox Code Playgroud)

在我的aspx.cs页面中,我有以下代码

string url = ConfigurationManager.AppSettings["URL"];

string strScript = "window.open(url?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);
Run Code Online (Sandbox Code Playgroud)

如果我写上面的代码,窗口不会打开,但是如果我在下面的代码中执行此操作,则会打开窗口.

string strScript = "window.open('/NG/Viewer/ViewerSummary.aspx?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);
Run Code Online (Sandbox Code Playgroud)

如何通过将值放入配置文件来打开窗口?
任何帮助表示赞赏.

谢谢.

Jos*_*hua 6

可能是您粘贴的代码有一些错误.第一个错误是你错过了window.open调用中的开头单引号.另一个错误是你实际上没有使用url变量.

试试这个:

string strScript = "window.open('" + url + "?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
Run Code Online (Sandbox Code Playgroud)