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

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default 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....
    Rich Guest

  2. Similar Questions and Discussions

    1. Win32::OLE->Initialize question
      I asked a little while ago about using 0x0040 (== BIF_NEWDIALOGSTYLE) in Win32::FileOp::BrowseForFolder because microsoft said it's one of those...
    2. Security permissions for Win32 LogonUser call.
      I am running my ASP.NET page under IIS in Windows 2000 Pro. I need to make a call to the Win32 LogonUser function to get a logon token. How can I...
    3. Question to WIN32::OLE
      Hi Folks is there any possibilty to copy excel worksheets in an ecxel-workbook with any win32-ole-functionality ? Thanks Pit
    4. Fw: Win32::OLE, Simple Question
      ----- Original Message ----- From: "William Martell" <willmartell@yahoo.com> To: "perl-win32-users" <perl-win32-users@listserv.ActiveState.com>...
    5. VRuby/Win32 Question
      This is a multi-part message in MIME format. ------=_NextPart_000_0126_01C3834F.594401B0 Content-Type: text/plain; charset="iso-8859-1"...
  3. #2

    Default Re: ASP.net & Win32 API (LogonUser) question...

    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
    [url]http://www.OdeToCode.com/blogs/scott/[/url]

    On 1 Nov 2004 17:06:19 -0800, [email]bobo456@hotmail.com[/email] (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....
    Scott Allen Guest

  4. #3

    Default Re: ASP.net & Win32 API (LogonUser) question...

    Hi Scott,

    Thanks for the response. I have tried this as well:
    <authentication mode="Windows"></authentication>
    <identity impersonate="True"/>

    I still only have Windows Auth checked in IIS and I still get
    Challenged eventhough I am using LogonUser to login the user to the
    server.

    Any other ideas?

    When I mentioned using both Windows Auth (IIS) & Forms Auth (Asp.net)
    I was trying to follow this example.
    [url]http://www.dotnetbips.com/displayarticle.aspx?id=201[/url]

    However, really my main goal is to login the user without getting the
    windows challenge, but to log them in manually so that they don't have
    to close the browser in order to sign in as a different user. Also I
    still want to retain the Windows Auth to check each file that is
    requested is being used by a valid user/group on the server.

    Thanks again...


    Scott Allen <bitmask@[nospam].fred.net> wrote in message news:<8n0eo05bq1cvnlj7edsreaqtp4tr7pe0aa@4ax.com>. ..
    > 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
    > [url]http://www.OdeToCode.com/blogs/scott/[/url]
    >
    Rich Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139