By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Passing Credentials

P: n/a
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.
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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/

Nov 12 '05 #2

P: n/a
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.


Martin Honnen <Ma***********@t-online.de> wrote in message news:<ub**************@TK2MSFTNGP10.phx.gbl>...
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

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.