Observe:
Whatever whatever;
using (var reader = new StreamReader(HttpContext.Server.MapPath("~/SiteMap.xml")))
{
var xmlSerializer = new XmlSerializer(typeof(Whatever));
whatever = xmlSerializer.Deserialize(reader) as Whatever;
}
Do note that the code above is C# and not JavaScript and there is no tilde in JavaScript. In JavaScript you need to do something like this:
function whereAmI() {
var url = window.location.href;
var urlChunks = url.split("/");
var url = "";
var matchMade = false;
urlChunks.forEach(function(chunk) {
if(!matchMade){
if (url == "http://" || url == "https://" || url == "http://localhost/" || url ==
"https://localhost/") {
if (chunk.toLowerCase() != "localhost") {
matchMade = true;
}
}
url = url + chunk.toLowerCase() + "/";
}
});
if (url.indexOf("?") > -1) {
urlChunks = url.split("?");
url = urlChunks[0] + "/";
};
if (url.indexOf("&") > -1) {
urlChunks = url.split("?");
url = urlChunks[0] + "/";
};
return url;
};
Why didn't I just use window.location.hostname you ask? Because .hostname will not find the base url for an IIS application which will have a base like so: http://localhost/whatever/
No comments:
Post a Comment