473,408 Members | 2,839 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,408 software developers and data experts.

ASP.NET Basic Authentication programmatically.

I am currently working on the application that need to simulate basic
authentication programmatically using user's credentials that are known.
Basically, the need is for a single sign on with a third party application.
The scenario is the following: a third party application (iChain I believe,
from Novell) is used to authenticate the user against Novell eDirectory. Once
authentication is complete a user is taken to a portal from which they are
able to access application A. Application A is a ASP.NET application running
on IIS 6. Right now I am thinking of having developers of portal to pass
user's credentials either as form fields or header value and then use those
credentials to simulate basic authentication in ASP.NET portal without the
password popup screen that is usually seen by users when entering a website
with Basic Authentication setup. I would assume that changing the header
value and adding "Authorization" header with username:password value in
Base64 would do the trick, however I realized that the Request is a read only
object within the application and cannot be modified. Right now I have the
following chunk of code that does what I need, however, its only does it when
called this way. since the request object I've created is a seperate request,
the only way to pass credentials is using that request object, however I need
to be able to authenticate user once and then permit browse of entire ASP.NET
application as authenticated user. I am not sure how to do it and I need some
help.

// I am getting user name and password for testing purpose
username = ConfigurationManager.AppSettings.Get("username");
password = ConfigurationManager.AppSettings.Get("password");

Response.Clear();

string usernamePassword1 = username + ":" + password;

// Request is created that will call a page named "Authenticated.aspx"
// Authenticated.aspx page contains a code for accessing Northwind database
using integrated security.
// This is done in order to use Basic Authentication with delegation to SQL
Server which will execute queries and stored
// procedures as that user. Currently, the code below works, but it only
works using the HttpWebRequest object I've created
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://"; +
ConfigurationManager.AppSettings.Get("reqUrl"));

CredentialCache mycache = new CredentialCache();
// Credentials are specified here
mycache.Add(new Uri("http://"; +
ConfigurationManager.AppSettings.Get("reqUrl")), "Basic", new
NetworkCredential(username, password));

req.Credentials = mycache;
// This header is not neccessary for the peice of code to work, however, I
was thinkng that it might actually
// stay with all of the request therefore making the basic authentication
work. It does not stay with all requests and response
// only with this current request.
req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new
ASCIIEncoding().GetBytes(usernamePassword1)));

HttpWebResponse res;
// I am calling getResponse method to get the response for the request
created above
res = (HttpWebResponse)req.GetResponse();

//Response.Write(res.StatusCode);

// Here I analyze the Status code and if it was OK then I am using
Server.Transfer to transfer
// the control to a different page. As I understand server.transfer keeps
the existing headers
// while Response.Redirect clears them out. I was thinking that by doing
server.transfer the header
// create above, "Authorization", will persist and allow the authentication
to stay for the session,
/// however, this does not work. Once I stop using res object, the
application is no longer authenticated
// and page fails to access the database since there are no credentials there.
if (res.StatusCode == HttpStatusCode.OK)

{

Debug.Write(Response.StatusCode);
Server.Transfer(ConfigurationManager.AppSettings.G et("reqUrlVirtual"));

}

else
Response.Write("Error: " + res.StatusCode);

I need to know how to make this scenario work. I need to enter ASP.NET
application and authenticate that user based on credentials passed to me
whichever way. If you know of a different solution, please let me know.

Sincerely,

Konstantin

Apr 10 '07 #1
0 15945

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
1
by: Oran | last post by:
I am trying to integrate an application into our extranets. The extranet technology has its own authentication system requiring a domain user but uses anonymous authentication (from the...
4
by: Joseph | last post by:
I have an intranet application that I setup using windows authentication through IIS basic authentication. Is there a way to set a timeout, so that after ten minutes the user will be prompted...
4
by: Dave | last post by:
Hi, Is there anyway to mimic forms authentication's loginUrl and RedirectFromLoginPage functionality using Windows authentication? We are developing intranet sites using basic authentication...
4
by: Barry | last post by:
The MS fix for IE broke how users access our site (if they patch their browsers), so I need a solution to get users logged onto our site transparently. Basically we used to log on to the site...
10
by: Will Gillen | last post by:
I have an ASP.NET application that is using Windows Integrated Authentication (IIS) (as opposed to Forms Authentication). When the user first logs into the application, IIS prompts the user for...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
7
by: Stanley | last post by:
Hi all! When I go to some web site, I have to provide username and password, like my router's web site. The question is the how can I programmatically capture the 'realm' (Like 'level_15_access'),...
3
by: Martin | last post by:
How does one set up basic authentication on an HttpListener? I know I need to set the HttpListener.AuthenticationSchemes to AuthenticationSchemes.Basic but then I'm unsure how and against what...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.