I have a custom usercontrol to logon users.

My Authentication setting:

  • Authentication Type: Windows

  • Enabled anonymous access

  • IIS Authentication Setting: Basic authentication

Now is the question how I can logon an anonymous user when he type a username + password and click login in the custom user control?

My current code in a IHttpModul:

IntPtr token = IntPtr.Zero;

                            bool result = User.LogonUser(userName,
                                                    out token);

                            if (result)
                                WindowsIdentity identity = new WindowsIdentity(token, "Basic");
                                WindowsPrincipal principal = new WindowsPrincipal(identity);

                                HttpContext.Current.User = principal;

But I get a login windows from internet explorer.

But the strang thing is when I click on the cancel button I am loged in into SharePoint!

Any suggestions?

  • Why would you put this code in a Module? It'd run for every request that way... – James Love Jan 22 '13 at 22:06
  • no.. I have some checks OF COURSE! :) before this code runs :) – pbojkowski Jan 23 '13 at 1:23
  • Have you tried moving this code into the codebehind of the user control? I'm betting your module runs after the SPRequestModule which handles the user identity... – James Love Jan 23 '13 at 8:10
  • Yes I have. But with no reaction. – pbojkowski Jan 23 '13 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.