Hi All,
I have created the custom login/landing page for sharepoint 2010 on visualstudio 2010 by referring to the online links. But the only problem is that, it asks me to enter my credentials first(the normal pop up windows authentication) instead of taking
me to the login page. Ideally, only when the user clicks the login button, this popup windows should appear. I have included the code behind for my page login.aspx below. Could someone please tell me what's wrong with this code. In the .aspx
file, I have just included a simple asp button and some html/css code to make the page look good.
I have also selected the custom login page in the central administration and gave my project's path.
using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.IdentityModel; namespace ShareLogin.Layouts.ShareLogin { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected override void OnInit(EventArgs e) { base.OnInit(e); hlInternalUsers1.Click += new EventHandler(hlInternalUsers1_Click); } void hlInternalUsers1_Click(object sender, EventArgs e) { if (null != SPContext.Current && null != SPContext.Current.Site) { Microsoft.SharePoint.Administration.SPIisSettings iisSettings = SPContext.Current.Site.WebApplication.IisSettings[Microsoft.SharePoint.Administration.SPUrlZone.Default]; if (null != iisSettings && iisSettings.UseWindowsClaimsAuthenticationProvider) { Microsoft.SharePoint.Administration.SPAuthenticationProvider provider = iisSettings.WindowsClaimsAuthenticationProvider; RedirectToLoginPage(provider); } } } private void RedirectToLoginPage(Microsoft.SharePoint.Administration.SPAuthenticationProvider provider) { string components = System.Web.HttpContext.Current.Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped); string url = provider.AuthenticationRedirectionUrl.ToString(); if (provider is Microsoft.SharePoint.Administration.SPWindowsAuthenticationProvider) { components = EnsureUrlSkipsFormsAuthModuleRedirection(components, true); } Microsoft.SharePoint.Utilities.SPUtility.Redirect(url, Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, this.Context, components); } //borrowed from Microsoft.SharePoint.Utilities.SPUtility 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; } } }