all groups > dotnet xml > november 2003 >
You're in the

dotnet xml

group:

Passing Credentials


Passing Credentials avargheese NO[at]SPAM comops.com.au
11/30/2003 9:35:08 PM
dotnet xml:
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
Re: Passing Credentials avargheese NO[at]SPAM comops.com.au
12/1/2003 2:34:07 PM
Thanks for the reply Martin.

But I was hoping to use the Credentials of the user that was using the
ASP.Net page.

So if the user did not have authorization to the URL i would send back
the error "you are not authorized". The user would then only be able
to retrieve XML from servers they were authorized to.






[quoted text, click to view]
Re: Passing Credentials Martin Honnen
12/1/2003 2:43:12 PM


[quoted text, click to view]

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-us/cpguide/html/cpconaspnetconfiguration.asp
--

Martin Honnen
http://JavaScript.FAQTs.com/
AddThis Social Bookmark Button