LOGON API and persistent cookies (Windows and Form authentication)

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

  1. #1

    Default LOGON API and persistent cookies (Windows and Form authentication)

    Hi i integrated windows and forms authentication on my apps. I created
    a logon page and used the windows authentication instead of managing
    the password and username myself. I can authenticate just fine, but
    when i go to set a persistent cookie it(the app) doesnt seem to let me.
    I have to always go through the login aspx file. All my code compiles
    and runs correctly accept for the part when the persistent cookie is
    suppose to be working. here's a snippet of my code:

    // this is just sitting in my Login class. not under any method.
    // it also allows me to authenticate through windows
    [DllImport("C:\\WINDOWS\\System32\\advapi32.dll")]
    public static extern bool
    LogonUser(String lpszUsername,
    String lpszDomain,
    String lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    out int phToken);

    // this validates the forms username and password

    public bool validateUser(string uid,string pwd)
    {
    try
    {
    int token1;
    bool loggedOn =
    LogonUser(uid,"NOI",pwd,2,0,out token1);
    IntPtr token2 = new IntPtr(token1);
    WindowsIdentity wi =
    new WindowsIdentity(token2);
    WindowsPrincipal wp =
    new WindowsPrincipal(wi);
    HttpContext.Current.User = wp;
    return true;
    }
    catch(Exception)
    {
    return false;
    }
    }
    // this supposedly creates the persistent cookie

    private void btnLogin_Click(object sender, System.EventArgs e)
    {
    /*
    * Trace debugging
    */
    Trace.Warn("LoginPage.btnLogin_Click(): Testing!");
    Trace.Warn( "Logger: " + LOG.Logger.Name );
    Trace.Warn( "Log debug: " + LOG.Logger.IsEnabledFor( Level.DEBUG ));
    LOG.Info("Login.btnLogin_Click: Testing!");

    if (validateUser(txtUsername.Text,txtPassword.Text))
    {
    // FormsAuthentication.RedirectFromLoginPage( txtUsername.Text,
    true );

    //
    FormsAuthentication.SetAuthCookie(Context.User.Ide ntity.Name,true);
    // Response.Redirect("Default.aspx");
    FormsAuthentication.SetAuthCookie(txtUsername.Text , true);
    FormsAuthentication.RedirectFromLoginPage( txtUsername.Text, true
    );
    }
    else
    {
    msgLogin.Text = "Invalid Login.";
    msgLogin.ForeColor = Color.Red;
    msgLogin.ToolTip = "Username and password do not match.";
    }
    }

    Ben Ong Guest

  2. Similar Questions and Discussions

    1. Custom Login Form for Windows Authentication?
      Hello: I need to have a custom login form page for a site with Windows Authentication and internally i make the 'authentication windows process'....
    2. ASP.NET Site/Webservice and Windows/Form authentication
      Hi All I have an ASP.NET site which runs using Windows(NTLM) authentication over SSL. I have a webservice where a vendor is only able to call...
    3. Cookies good enough for logon?
      I am currently working on a new version of a software package for managing webcomic sites. In older versions I relied on the user setting up...
    4. Persistent Authentication Ticket Problem
      I am using Forms Authentication in my application. Once the user is authenticated, I create an authentication ticket with the database login...
    5. Network logon authentication
      I have a peer to peer network of all WinXP Pro SP1 computers. Lately, I have been unable to connect to one particular computer using any sort of...
  3. #2

    Default Logonuser API or Windows Login API

    Here is the usage of LogonUser API in detail.

    http://codingforpassion.blogspot.com/2011/07/windows-logon-api-for-net.html

    Thanks,
    Srikanth.V
    SrikanthVemulapally 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