admin管理员组文章数量:1421564
i want to acess the web config value in javascript
config entry:
<add key ="RootPath" value ="C:\Test" />
javascript code:
var v1 = '<%=ConfigurationManager.AppSettings["RootPath"].ToString() %>'
The output that i am getting is
C:Test
but what i want is C:\Test
Any idea how to acheive this ?
i want to acess the web config value in javascript
config entry:
<add key ="RootPath" value ="C:\Test" />
javascript code:
var v1 = '<%=ConfigurationManager.AppSettings["RootPath"].ToString() %>'
The output that i am getting is
C:Test
but what i want is C:\Test
Any idea how to acheive this ?
Share Improve this question edited Oct 21, 2011 at 9:26 Falcon 6501 gold badge9 silver badges24 bronze badges asked Oct 21, 2011 at 7:59 user339160user339160 2- 1 as side note: I would really not call directly the ConfigurationManager from JavaScript. you could have that value rendered in an hidden field or worst case in a public static method of the page you access the ConfigurationManager and from JavaScript you call the public method, it starts getting nasty having client code reading config file directly, in my opinion... – Davide Piras Commented Oct 21, 2011 at 8:04
- if you are using 4.0 you can use HttpUtility.JavaScriptStringEncode() – deostroll Commented Oct 22, 2011 at 10:00
4 Answers
Reset to default 4Try this
ConfigurationManager.AppSettings["RootPath"].ToString().Replace(@"\", @"\\")
var v1 = '<%= ConfigurationManager.AppSettings["RootPath"].Replace(@"\",@"\\") %>'
ToString() is excess
if you adding this
<add key ="RootPath" value ="C:\\Test" />
then you will retrive like "C:\Test"
.
Its behavior of .
some thing like this
var defaults = {inactivity: <%=ConfigurationManager.AppSettings["Inactivity"] %> }
Refer to the Read Configuration settings from 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#.
本文标签: cWebconfig value in javascriptStack Overflow
版权声明:本文标题:c# - Web.config value in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745353016a2654886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论