简体   繁体   English

从web.config获取URL

[英]Getting a URL from web.config

I am trying to store a URL in the configuration file, but it does not work when I retrieve the URL from the file 我正在尝试将URL存储在配置文件中,但是当我从文件中检索URL时它不起作用

Below is my code 下面是我的代码

In web.config, I have 在web.config中,我有

 <add key="URL" value="/NG/Viewer/ViewerSummary.aspx"/>

In my aspx.cs page, I have the following code 在我的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);

the window does not open if I write the above code, but window opens if I do this below code. 如果我编写上面的代码,则窗口不会打开,但是如果我编写下面的代码,则窗口将打开。

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);

How can I open the window by putting the value in the config file? 如何通过将值放入配置文件来打开窗口?
Any help is appreciated. 任何帮助表示赞赏。

Thanks. 谢谢。

It could be that your code that you have pasted has a couple errors. 您粘贴的代码可能有几个错误。 The first error is you're missing the opening single quote in the call to window.open. 第一个错误是您在对window.open的调用中缺少开头的单引号。 The other error is you aren't actually using the url variable. 另一个错误是您实际上没有使用url变量。

Try this: 尝试这个:

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');";
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);

See the article listed below for using URLEncode method. 请参阅下面列出的有关使用URLEncode方法的文章。

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx http://msdn.microsoft.com/zh-CN/library/zttxte6w.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM