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

From: Rich (bobo456_at_hotmail.com)
Date: 11/02/04


Date: 1 Nov 2004 17:06:19 -0800

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....



Relevant Pages

  • RE: Beginners Questions
    ... We do use Windows form on the presentation layer which is on ... terminal server and call web services on the business logic side. ... of using "proxy" authentication on SQL Server. ... > I have written an app with a Windows Forms UI that is deployed to clients ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: Cross domain exchange server access, popup boxes....
    ... LogonUser/ImpersonateLoggedOnUser or run your app as an admin to be able to ... > exchange server and access the data. ... > windows service so a popup box won't fly at all. ... > LogonUser system call to impersonate the user that can access the ...
    (microsoft.public.win32.programmer.messaging)
  • Re: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
    ... app works perfectly on Windows 2000 server, but after moving same app to ... I am running my app on HP DL380 server, on a HP ProCurve switched network, ...
    (microsoft.public.inetserver.asp.general)
  • Re: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
    ... app works perfectly on Windows 2000 server, but after moving same app to ... I am running my app on HP DL380 server, on a HP ProCurve switched network, ...
    (microsoft.public.sqlserver.programming)
  • Re: Permissions - giving "everyone" full permissions is bad ?
    ... >Now I want to deploy this app to a windows 2003 web edition server, so my customers can test the app. ... >So I go into the properties for the dir where this TXT file is, and adds ASPNET user and gives it "modify" permissions - no luck! ...
    (microsoft.public.dotnet.framework.aspnet)