I would like to have a xml file on my website that holds temporary information from a database. When I use VSCode to do so, it works just fine; but when I use my actual ASP.Net Web Application, it does not. I assume it has to do with the file path that I am using, any help would be greatly appreciated!
ASP.Net
C#
string path = Server.MapPath("~/App_Data/phones.xml");
foreach (var pm in Model)
{
// add each model to xml
}
JS
const MakePhoneOBJ = (xmlFile) => {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
xmlFunc(this);
}
};
xmlhttp.open("GET", xmlFile, true);
xmlhttp.send();
}
const xmlFunc = (xml) => {
var xmlDoc = xml.responseXML;
var root = xmlDoc.getElementsByTagName("Element");
for (let i = 0; i < root.length; i++) {
// Do something with the file contents
}
}
HTML
<body onload="MakePhoneOBJ('@path');">
</body>
question from:
https://stackoverflow.com/questions/66067458/where-can-i-store-an-xml-file-for-the-browser-to-read-using-asp-net-mcv 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…