473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing Credentials

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
2 7489


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ole Hanson | last post by:
Hi I am trying to pass a credentials object to a webpage programmatically. I have a winApp (C#) that I want to be able to open a webpage (by starting IE), but the credentials required by IIS...
3
by: Das | last post by:
Hi all, I'm writig an application that sends an http request to java servlet file. I have to pass an xml file to the servlet. How should I pass xml file to the file. When I try to access the...
7
by: Steve Drake | last post by:
All, I am doing a WEBDAV request and I want to pass the users Credentials to the webdav server, eg some code like : Request.Credentials = CredentialCache.DefaultCredentials; This does not...
7
by: Wade Wegner | last post by:
Hello, I have been desperately trying to programmatically authenticate a windows user, create their credentials, and then redirect them to a different server while passing the credentials at the...
1
by: jadher | last post by:
I try to access an asp page in a machine that has windows integrated authentication turned on. I use System.Net.Networkcredentials as well as System.Net.Webrequest and Webresponse. I receive...
4
by: Dan Higman | last post by:
I'm sure this is easy and I'll be embarrassed when I see the answer, but I just can't figure this one out. Using .Net/ASP 1.1 on a server using integrated authentication-- I have a web page...
3
by: GRB | last post by:
My webiste has integrated windows authentication. I need to pass a clients credentials (username, password) to my site without the login pop up. I send the client to an anonymous page, get an...
2
by: Jay Balapa | last post by:
Hello, Win Forms app is able to connect to my webservice passing credentials as follows- myService.Credentials=System.Net.CredentialsCache.DefaultCredentials; Compact Framework does not...
4
by: Kris Kennaway | last post by:
I want to make use of UNIX credential passing on a local domain socket to verify the identity of a user connecting to a privileged service. However it looks like the socket module doesn't implement...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.