473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15965

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

Similar topics

7
9259
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
1979
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
11789
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
4804
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
2050
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
13808
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
2515
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
7593
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
15765
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
7002
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
7203
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...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4908
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...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.