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 am creating a Claims based authentication using PowerShell. I am enabling both Windows authentication and FBA. My code will look as follows:

    $authMethod = "NTLM"
Write-Output "Creating $title web application on port $port..." 
$waexe = "New-SPWebApplication -Name $title -ApplicationPool $title -ApplicationPoolAccount(Get-SPManagedAccount `$managedAccount)"
$waexe += " -Url $waurl -Port $port"
$waexe += " -DatabaseName $databaseName"
$waexe += " -AuthenticationMethod $authMethod"
$winap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos 
$fbap = New-SPAuthenticationProvider -ASPNETMembershipProvider $membership -ASPNETRoleProviderName $rolemanager             
$waexe += " -AuthenticationProvider (`$winap,`$fbap)"
if($signInRedirectUrl -ne $null)
    $waexe += " -SignInRedirectURL $signInRedirectUrl"
$prxyGroup = Get-SearchProxyGroup
if($prxyGroup -ne $null)
    $waexe += " -ServiceApplicationProxyGroup `$prxyGroup"
$waexe += " -ErrorVariable err -ErrorAction SilentlyContinue"   
$waexe += " | Out-Null"     

Write-Output $waexe

Invoke-Expression $waexe

The application gets created fine. When i try to browse the site, it redirect to custom sign-on page.

But if something WRT to FBA has failed, it wouldn't allow me to login using Windows authentication. When i try to access default login page "_login/default.aspx", it still redirects to custom sign-in page.

How can i login using windows authentication. My crawl component can successfuly crawl the site using Windows authentication.

share|improve this question

As I noted in my comment above, I think navigating to "_windows/default.aspx" will redirect you to the custom login page.

I think the best approach would be to add an option to your custom login page to login using Windows Authentication. You can present the user with the username/password as being the default method for login, but have a link or button somewhere on the page where they can login using Windows Authentication...maybe call it Admin Login. You could have the link or button call the following code to redirect to the page associated with logging in via Windows Authentication.

    private void GetWindowsAuthenticationProvider()
        Microsoft.SharePoint.Administration.SPIisSettings settings = Microsoft.SharePoint.SPContext.Current.Site.WebApplication.GetIisSettingsWithFallback(Microsoft.SharePoint.SPContext.Current.Site.Zone);
        foreach (Microsoft.SharePoint.Administration.SPAuthenticationProvider provider in settings.ClaimsAuthenticationProviders)
            if (provider is Microsoft.SharePoint.Administration.SPWindowsAuthenticationProvider)
                string components = System.Web.HttpContext.Current.Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);
                string url = provider.AuthenticationRedirectionUrl.ToString();
                Microsoft.SharePoint.Utilities.SPUtility.Redirect(url, Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, this.Context, components);
share|improve this answer
Much better answer then mine (+1). In recent project I had some problems implementing similar code. Users were never asked for windows credentials so I ended with redirecting them to _windows/default.aspx (look at my edited answer). After that everything start to work as expected. Any idea why? (if you debug your code you will notice that url = '_windows/default.aspx') – Vedran Rasol Jul 23 '11 at 20:45
Right...the page it redirects to is "_windows/default.aspx", but when you type an address into the address bar of a web browser it's not performing a redirect operation. Given that, I'm going to assume that the code-behind for the windows auth page is looking for a redirect. – Rob D'Oria Jul 23 '11 at 21:28

You can log using windows authentication by accessing '_windows/default.aspx'


After reading Robs comment I did some double checking. By simply entering '_windows/default.aspx' in your browser you will be redirected to default (or custom) login page. But if you are using this block of code in your custom login page you will be asked for windows credendials:

protected void Page_Load(object sender, EventArgs e)
    var components = Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);
    SPUtility.Redirect("/_windows/default.aspx", SPRedirectFlags.Default, Context, components);

This piece of code was source for my answer. My mistake was that it was not included in original answer.

share|improve this answer
I think navigating to "_windows/default.aspx" will redirect you to the custom login page as well. – Rob D'Oria Jul 23 '11 at 13:21

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.