Angelo Vargheese wrote:
Hi,
I am trying to retrieve XML created by ASP pages on different servers
and display them on a single ASP.Net page.
I was planning to use the XMLDocument and XMLResolver objects like
below:
xmlResolver.Credentials = CredentialCache.DefaultCredentials
xmlDoc = New XmlDocument
xmlDoc.XmlResolver = xmlResolver
Try
xmlDoc.Load(URL) '
Catch ex As Exception
Throw ex
End Try
The URLs are secured using integrated windows authentication. When I
connect to the page I get the exception "The remote server returned an
error: (401) Unauthorized". But I can use the URL in IE and it
displays the XML properly.
Also if I change the line
xmlResolver.Credentials = CredentialCache.DefaultCredentials
to
xmlResolver.Credentials = New NetworkCredential _
("myid", "mypassword", "mydomain")
the code works without a problem.
I don't want to hard code the credentials in my code.
I am not sure if I am using the objects correctly.
If anybody knows what's wrong with the code or a better way to pass
through user credentials it would be greatly appreciated.
You can set up a Web.config file for your ASP.NET application and store
application specific data like the credentials there. That avoids
hardcoding the credentials in the code.
Here is an example file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="god" value="Kibo" />
</appSettings>
</configuration>
You can add any data needed with further <add> elements.
Then inside your ASP.NET code you need to import SystemConfiguration
and then you can read
ConfigurationSettings.AppSettings["god"]
as in the following example
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
void Page_Load () {
string appKey = ConfigurationSettings.AppSettings["god"];
if (appKey != null) {
aLabel.InnerText = appKey;
}
}
</script>
<html>
<head>
<title>reading application settings</title>
</head>
<body>
<p>
app key is
<span id="aLabel" runat="server"></span>
</p>
</body>
</html>
The IIS server is not serving Web.config files to the browser.
You can find more about Web.config at
http://msdn.microsoft.com/library/en...figuration.asp
--
Martin Honnen
http://JavaScript.FAQTs.com/