Javascript - .html与.net的.aspx对于.config中的值 [英] Javascript - .html vs. .net's .aspx for values in .config

查看:84
本文介绍了Javascript - .html与.net的.aspx对于.config中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在html和aspx文件的脚本块中,我使用下面这段代码检索配置文件中的值:

In the script block in both html and aspx file, I use this piece of code below to retrieve the values in the config file:

var devServer = "<%=ConfigurationManager.AppSettings['devServer'].ToString() %>";



在aspx中,可以很好地检索配置文件中的值。但是,在html中,这段代码不起作用。怎样才能解决这个问题?谢谢。



我尝试过:



JavaScript - .html与.Net的.aspx对于.config中的值


In the aspx, the value in the config file is retrieved well. However, in the html, this piece of code does not work. How can this problem be solved? Thanks.

What I have tried:

JavaScript - .html vs. .Net's .aspx for values in .config

推荐答案

将继续分享我对此的看法,但你可以在google中进一步查看这个并查看正确性,可以深入了解。



要理解这一点,你必须了解aspx页面是如何工作的,即如何在服务器端处理它,以便最终一些客户端脚本和html标记可以是服务于所请求的客户。



HTML页面通过网络服务器直接提供给请求的客户端,因此,没有服务器端处理服务于普通的html页面。虽然aspx页面必须经过某些过程。为什么?因为您的网络浏览器不理解asp.net而不是它需要html,css和javascript。因此,当客户端请求aspx页面时,服务器上的IIS接收请求并发送到ASP.Net引擎,该引擎通过解析所有依赖项来进一步处理页面内容,以便最终可以将一些html标记和脚本提供给客户端。



现在进入您的代码块,可以使用服务器页面访问ConfigurationManager类及其属性。纯HTML页面不会经过ASP.Net引擎进程,显示的变量也不会被配置中的值替换。



有人,请纠正我,如果我我错了。



谢谢:)
Will go ahead to share my view on this but you can go further to look this in google and check the correctness and can get in depth knowledge.

To understand this you have to understand how a aspx page works i.e, how it is processed at the server end so that finally some client side script and html markup can be served to the requested client.

An HTML page is directly served via the webserver to the requested client so, no server side processing happens to serve plain html pages. While an aspx page has to go through certain processes. Why? Because your web browser doesn't understand asp.net rather it expects html, css and javascript. So when client requests for an aspx page, the IIS at server receives the request and sends to the ASP.Net engine which further process the content of the pages by resolving all the dependencies so that finally some html markup and script can be served to the client.

Now coming to your code block, ConfigurationManager class and it's properties can be accessed with server pages. A plain HTML page will not undergo process with ASP.Net engine and the shown variable will not be replaced by the value from configuration.

Someone, please correct me if I am wrong here.

Thanks :)


这篇关于Javascript - .html与.net的.aspx对于.config中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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