从JavaScript web.config中读取 [英] Reading web.config from JavaScript

查看:862
本文介绍了从JavaScript web.config中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里,我可以在web.config中使用JavaScript读取配置值什么办法?
我为什么要那样做?

IS there any way that I can read config values in web.config with javascript ? Why would I want to do that ?

我在我的网站上的计时器,它会弹出一个模式对话框与倒数计时器(倒计时2分钟),如果用户处于非活动状态20分钟。如果用户不响应,它会记录他。如果他这样做,它坪到服务器(保持会话),并保持会话的活

I have a timer in my website which would pop up a modal dialog with a count down timer (count down for 2 minutes) if the user is inactive for 20 minutes. If the user does not respond, it logs him out. If he does, it pings to the server (to maintain the session) and keeps the session alive

这15分钟路程,在js文件硬codeD。我宁愿想从一个配置文件把它捡起/其他一些文件不是它很难codeD插入JS

This 15 minutes is hardcoded in the js file. I would rather want to pick it up from a config file/some other file than having it hard coded into the JS

这里是code段

$.fn.idleTimeout = function(options) {
    	var defaults = {
                    //I would like to pick these values from some config file
    		inactivity: 900000, //15 minutes 
    		noconfirm: 120000, //2 minutes
    		sessionAlive: 900000, //15 minutes
    		click_reset: true,
    		logout_url: '/Views/Pages/Timeout.aspx' 
    	}

有什么建议?

编辑:这是在一个单独的JS文件。这样做<%=%>会给错误非法XML字符
活动[关于此错误BREAK]:其中,%= ConfigurationManager.AppSettings [无为]%>;

This is in a separate js file. Doing <%=%> would give error "illegal XML character [Break on this error] inactivity: <%=ConfigurationManager.AppSettings["Inactivity"] %>;"

推荐答案

您可以生成从ASP.NET你的JavaScript。

然后简单地写在服务器端的设置到你的 VAR默认是这样的:

Then simply write the settings at the server-side to your var defaults like this:

var defaults = {
    inactivity: <%=ConfigurationManager.AppSettings["Inactivity"] %>
}

编辑:

如果你想保持你的JavaScript静态JS文件,你仍然可以初始化 VAR默认从一个小&LT;脚本&GT; 通过ASP.NET应用程序渲染。您的设置将是全球性的,就像的AppSettings 的web.config

If you want to keep your JavaScript in static js files, you can still initialize your var defaults from a small <script> rendered by your ASP.NET application. Your settings would be global, just like the AppSettings in web.config.

这篇关于从JavaScript web.config中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆