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

When a user on a non-company asset (i.e. not connected to the domain) logs on to our SharePoint site, they are presented with a default windows popup dialog. We would like to remove this dialog and provide a log in form on our top-level site (which is set for anonymous access).

Is it possible to log a user in programmatically under Windows Authentication? How would I do this?

Note: The site MUST be set for Windows Authentication, so Forms Authentication with the ActiveDirectoryMembershipProvider won't work.

A little more context: The users will be connected to the internal network, but using their own computers (like students that connect to a school network), so VPNs are unnecessary. We are using MOSS 2007.

share|improve this question
up vote 1 down vote accepted

The Microsoft Threat Management Gateway 2010 can do this. See answers to this related question.

share|improve this answer

very do-able and not very difficult :-)

Read here:

The following two lines of code should do the job:

SecurityToken tk = SPSecurityContext.SecurityTokenForFormsAuthentication(
new Uri(SPContext.Current.Web.Url), "ADProvider", null,Username.Text, Password.Text);

if (tk != null)
        SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
share|improve this answer
I'm using MOSS 2007, there doesn't appear to be a SPSecurityContext class available for 2007. – Kyle Trauberman Jul 8 '11 at 16:08
Hi There. Sorry for not responding in a loooong time. So basically, you want to also use your normal users with AD Auth, and some other users with Anonymous? Why not just extend the web application and have the second web app use Anonymous? – Fox Feb 10 '12 at 6:55
We ended up scrapping this project, so its irrelevant now. The 3rd party product we were using required Windows authentication (it tied it self in with FIM). We wanted to customize the login screen so users would be presented with a login form on a page, instead of the generic windows login popup prompt (our users would be coming in from outside the domain, so wouldn't auth automatically). My idea was to create a login page and allow anonymous access for that, then redirect to the site requiring auth after login. – Kyle Trauberman Feb 10 '12 at 15:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.