SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.