Guest User

Guest User

  • Tech Writer
  • 4
  • 2.6k

SharePoint 2013 Custom Sign in page

Jun 4 2015 10:09 AM
I am developing a custom sign in page for SharePoint 2013 web application with claims authentication (windows NTLM). The problem is when user visits the site, the windows prompt for username password before custom sign in page loads. Instead the user should be redirected directly to Custom sign in page.
 
How to disable the windows prompt. Following is the code for sign in page
 
Following is code for used for sign in button
 

protected void login_Click(object sender, EventArgs e)
{
SPIisSettings iisSettings = SPContext.Current.Site.WebApplication.IisSettings[SPUrlZone.Default];
SPAuthenticationProvider provider = iisSettings.WindowsClaimsAuthenticationProvider;
RedirectToLoginPage(provider); // This should cause automatic sign in
}

private void RedirectToLoginPage(SPAuthenticationProvider provider)
{
string components = HttpContext.Current.Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);
string url = provider.AuthenticationRedirectionUrl.ToString();
if (provider is SPWindowsAuthenticationProvider)
{
components = EnsureUrlSkipsFormsAuthModuleRedirection(components, true);
}
SPUtility.Redirect(url, SPRedirectFlags.Default, this.Context, components);
}

private string EnsureUrlSkipsFormsAuthModuleRedirection (string url, bool urlIsQueryStringOnly)
{
if (!url.Contains("ReturnUrl="))
{
if (urlIsQueryStringOnly)
{
url = url + (string.IsNullOrEmpty(url) ? "" : "&");
}
else
{
url = url + ((url.IndexOf('?') == -1) ? "?" : "&");
}
url = url + "ReturnUrl=";
}
return url;
}

private SPAuthenticationProvider GetAuthenticationProvider(string providerName)
{
SPIisSettings iisSettings = SPContext.Current.Site.WebApplication.IisSettings[SPUrlZone.Default];

foreach (SPAuthenticationProvider currentProvider in iisSettings.ClaimsAuthenticationProviders)
{
if (currentProvider.DisplayName.ToLower() == providerName.ToLower())
{
return currentProvider;
}
}

return null;
} 

Answers (1)