473,387 Members | 1,619 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.

ASP.net & Win32 API (LogonUser) question...

I am running IIS6 on a Win2k3 server.

I have an ASP.Net app (C#) that a user logs into and then I use
LogonUser to validate them and log them onto the server. I have
Windows Authentication ONLY checked on the site in IIS.

My problem is that eventhough I am using LogonUser to log on to the
server as the user, I am still getting the Windows Authentication
Challenge (login window).

There are groups/users setup on the server for this app, so I don't
want to turn windows auth off because I am afraid my LogonUser usage
is only seeing if they have access to the server not to that
particular file.

Am I missing something? I was hoping LogonUser would act as if the
user had entered their own info into the windows challenge login
window.

I plan use forms auth to keep track of session later on, so right now
I have my web.config setup as:
<authentication mode="Forms">
<forms name="frmLogin" loginUrl="login.aspx"></forms>
</authentication>
<identity impersonate="True"/>

Here is most of my C# code:
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern int LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

[DllImport("ADVAPI32.DLL")]
public static extern int RevertToSelf();

[DllImport("ADVAPI32.DLL")]
public static extern int ImpersonateLoggedOnUser(IntPtr phToken);
IntPtr tok = IntPtr.Zero;

private void btnLogin_Click(object sender, System.EventArgs e)
{
if(impersonateValidUser (txtUser.Text
, "cgi.securenet01.com",
txtPassword.Text))
{ Response.Redirect("reportLogin.aspx");
undoImpersonation();
}
else { lblError.Text="Login Failed"; }
}
public void undoImpersonation()
{ RevertToSelf(); }
public Boolean impersonateValidUser(String name
, String domain, String
passwd)
{
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_PROVIDER_DEFAULT = 0;
int result = LogonUser(name, domain, passwd,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref tok);
if(result!= 0)
{ int result1 = ImpersonateLoggedOnUser(tok);
if(result1 != 0) { return true; }
else { return false; }
}
else { return false; }
}

Any help is appreciated....
Jul 21 '05 #1
1 2873
Hi Rich:

I'm a little confused. You want to use Windows authentication but you
have the web.config setup for Forms authentication? Forms auth will
always force the browser to prompt the user to login. This setting in
web.config will trump the IIS setting.

I think you want to change the web.config to Windows authentication
only and deny anonymous access. Once you do this there is no need to
use LogonUser, you can have the impersonate="True" in the web config
and the request will access local resources using the client's
identity. If the client is not in a group allowed to see a particular
file the server will deny authorization.

Tracking the user's session is a different issue and independent of
how the app authenticates and authorizes the user. You can still have
session state without forms authentication.

Making sense?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 1 Nov 2004 17:06:19 -0800, bo*****@hotmail.com (Rich) wrote:
I am running IIS6 on a Win2k3 server.

I have an ASP.Net app (C#) that a user logs into and then I use
LogonUser to validate them and log them onto the server. I have
Windows Authentication ONLY checked on the site in IIS.

My problem is that eventhough I am using LogonUser to log on to the
server as the user, I am still getting the Windows Authentication
Challenge (login window).

There are groups/users setup on the server for this app, so I don't
want to turn windows auth off because I am afraid my LogonUser usage
is only seeing if they have access to the server not to that
particular file.

Am I missing something? I was hoping LogonUser would act as if the
user had entered their own info into the windows challenge login
window.

I plan use forms auth to keep track of session later on, so right now
I have my web.config setup as:
<authentication mode="Forms">
<forms name="frmLogin" loginUrl="login.aspx"></forms>
</authentication>
<identity impersonate="True"/>

Here is most of my C# code:
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern int LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

[DllImport("ADVAPI32.DLL")]
public static extern int RevertToSelf();

[DllImport("ADVAPI32.DLL")]
public static extern int ImpersonateLoggedOnUser(IntPtr phToken);
IntPtr tok = IntPtr.Zero;

private void btnLogin_Click(object sender, System.EventArgs e)
{
if(impersonateValidUser (txtUser.Text
, "cgi.securenet01.com",
txtPassword.Text))
{ Response.Redirect("reportLogin.aspx");
undoImpersonation();
}
else { lblError.Text="Login Failed"; }
}
public void undoImpersonation()
{ RevertToSelf(); }
public Boolean impersonateValidUser(String name
, String domain, String
passwd)
{
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_PROVIDER_DEFAULT = 0;
int result = LogonUser(name, domain, passwd,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref tok);
if(result!= 0)
{ int result1 = ImpersonateLoggedOnUser(tok);
if(result1 != 0) { return true; }
else { return false; }
}
else { return false; }
}

Any help is appreciated....


Jul 21 '05 #2

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

Similar topics

0
by: DotNet | last post by:
hi. I am trying to use C# or VB.NET to write a popup killer program(kills IE popup windows). I have looked up info on google and found that the FindWindow function in win32 API is probably the...
1
by: Eitan | last post by:
Hello, I am using Visual Studio.net 2003. I am trying to find how to create Win32 DLL & Win32 Static Library. When going through the wizard it does not show me the option for these two project...
0
by: DotNet | last post by:
hi. I am trying to use C# or VB.NET to write a popup killer program(kills IE popup windows). I have looked up info on google and found that the FindWindow function in win32 API is probably the...
2
by: Can Balioglu | last post by:
Hi, Is there a library in platform sdk for using regular expressions in win32? Thanks for replies...
1
by: Rich | last post by:
I am running IIS6 on a Win2k3 server. I have an ASP.Net app (C#) that a user logs into and then I use LogonUser to validate them and log them onto the server. I have Windows Authentication ONLY...
4
by: BrianDH | last post by:
Hi I am working on a C# Windows Application that builds an invoice (CR) converts to PDF and attach to email one at a time. This works untill my invoice count get over 40 to 50 invoices then I...
3
by: Soneji | last post by:
Hello yet again, I know this is long, and I apologize... but hang in there! :) I've been learning C++, and I can't get enough. I've been finding out more, and more about it online, ever since...
48
by: teapot | last post by:
If I compile this program int main(void) { return 0; // foo bar baz } with "lc -A -ansi89 foo.c"
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
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
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...

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.