【发布时间】:2015-05-11 16:44:42
【问题描述】:
好的,情况就是这样。我有一个在 MVC 4 应用程序中运行的经典 ASP 网站。我需要经典的 ASP 网站才能从 web.config 文件的 appsettings 部分获取密钥。
这是我的功能:
' Imports a site string from an xml file (usually web.config)
Function ImportMySite(webConfig, attrName, reformatMSN)
Dim oXML, oNode, oChild, oAttr, dsn
Set oXML=Server.CreateObject("Microsoft.XMLDOM")
oXML.Async = "false"
oXML.Load(Server.MapPath(webConfig))
Set oNode = oXML.GetElementsByTagName("appSettings").Item(0)
Set oChild = oNode.GetElementsByTagName("add")
' Get the first match
For Each oAttr in oChild
If oAttr.getAttribute("key") = attrName then
dsn = oAttr.getAttribute("mysite")
ImportMySite = dsn
Exit Function
End If
Next
End Function
这里是函数调用代码:
msn = ImportMySite("web.config", "mysite", false)
所以当我调用这个函数时,我得到的值总是空白或空。我不确定我哪里出错了,我是 XML 的新手,所以也许我遗漏了一些完全明显的东西。我已经搜索了问题,但使用经典 ASP 找不到与此相关的任何内容。
任何帮助将不胜感激。
【问题讨论】:
-
Set oXML=Server.CreateObject("Msxml2.DOMDocument.6.0")将调用最新版本的 Microsoft XML 处理器。 -
谢谢你,我已经更新了我的代码。
标签: asp.net asp.net-mvc asp-classic web-config