[英]Web.config value in javascript
i want to acess the web config value in javascript 我想在javascript中访问web配置值
config entry: 配置条目:
<add key ="RootPath" value ="C:\Test" />
javascript code: javascript代码:
var v1 = '<%=ConfigurationManager.AppSettings["RootPath"].ToString() %>'
The output that i am getting is 我得到的输出是
C:Test
but what i want is C:\\Test 但我想要的是C:\\ Test
Any idea how to acheive this ? 知道如何实现这个吗?
尝试这个
ConfigurationManager.AppSettings["RootPath"].ToString().Replace(@"\", @"\\")
some thing like this 这样的事情
var defaults = {inactivity: <%=ConfigurationManager.AppSettings["Inactivity"] %> }
Refer to the Read Configuration settings from javascript . 请参阅javascript中的“ 读取配置”设置 。 If you are getting the config value like
如果你得到配置值,如
C:\Test
change the config entry to C:\\\\Test
and in C# especially in paths the \\\\
will be automatically converted in to \\
because slash will be escaped by using escape sequence, because anything that begins with a backslash ('\\') is termed as escape sequence in C#. 将配置条目更改为
C:\\\\Test
并在C#中特别是在路径中, \\\\
将自动转换为\\
因为斜杠将使用转义序列进行转义,因为以反斜杠('\\')开头的任何内容都被称为作为C#中的转义序列。
var v1 = '<%= ConfigurationManager.AppSettings["RootPath"].Replace(@"\",@"\\") %>'
ToString()是多余的
if you adding this 如果你加上这个
<add key ="RootPath" value ="C:\\Test" />
then you will retrive like "C:\\Test"
. 然后你将像
"C:\\Test"
那样进行翻版。 Its behavior of .net. 它的行为.net。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.