[英]How to read Session timeout value from web.config using javascript in JS file
Can anyone please guide me to read the value of Session timeout value using javascript contained in a .js file. 任何人都可以引导我使用.js文件中包含的javascript来读取会话超时值的值。
I need to access the value in a javascript file and process the value. 我需要访问javascript文件中的值并处理该值。
I tried to follow the below approach in a test.js file but it is not working: 我试图在test.js文件中遵循以下方法,但无法正常工作:
var sessionTimeout = <%= Session.Timeout %>;
alert(sessionTimeout);
Your problem is that .JS files are not executed so they do not contain the Session.Timeout variable. 您的问题是.JS文件未执行,因此它们不包含Session.Timeout变量。
You can do two things: 您可以做两件事:
Registering your JS 注册您的JS
See: http://msdn.microsoft.com/en-us/library/aa479011.aspx#aspnet-usingjavascript_topic07 请参阅: http : //msdn.microsoft.com/zh-cn/library/aa479011.aspx#aspnet-usingjavascript_topic07
Page.RegisterClientScriptBlock("MyScript", _
"<script language=javascript src='MyJavaScriptFile.js'>")
I have share m code which I use for connection string from this code you can replace logic for session. 我有共享m代码,该代码用于连接字符串,您可以替换会话逻辑。
<script language="javascript" type ="text/javascript">
function ReadWebConfig()
{
var strCon = '<%=ConfigurationManager.ConnectionStrings["MysqlCon"].ConnectionString %>'
alert(strCon);
var strTemp = '<%=ConfigurationManager.AppSettings["WordTemplate"].ToString() %>'
alert(strTemp);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.