Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
การสร้างฟอร์มสำหรับการ Login ใน share point 2010 ที่เป็นแบบของเราเอง
1. Login SharePoint 2010
Problem
Many applications need Claim Based Authentication instead of Classic Mode Authentication.
The Form Based Authentication (FBA) is one type of Claim Based Authentication. The default
login page of FBA in SharePoint 2010 is very simple which only provides a simple Login
control with the user name, password and remember me option. But many developers want
to implement a customized login page for a better looking experience or more options
according to business requirements.
Solution
This article will demonstrate how to create a custom login page for a SharePoint site using
Visual Studio 2010 and deploy it in a server farm. It will also include how to change the default
login page URL from the Central Administration Application Provider Settings.
Step 1:
Create a new project type “Empty SharePoint Project” in Visual Studio 2010 as showed
below:
2. Provide a Project name and Press “OK”. You will be prompted with a Wizard to specify the
SharePoint site where you want to deploy the custom login page. You can validate the site
URL to ensure that your site is fine to deploy in this solution. Remember that you have to
choose Deploy as Server Farm solution instead of deploying as a sandboxed solution
(default selected as below). Otherwise you will get an error when you deploy the solution:
“The deployment type "TemplateFile" of file "CustomLogin.aspx" in the Project Item
"Layouts" is not compatible with a Package in a Sandboxed Solution”. Because Layout is
root place to deploy in SharePoint server farm which is mapped
{SharePointRoot}TemplateLayouts.
So you will select Deploy as Server Farm solution after validation of the site URL.
3. Then "Click to Finish” and the project creation should be successful.
Step 2:
You have to add a new Application Page with a right-click on the project Solution Explorer
-> New item to create Custom Login page
4. The form will auto-generate some code where you:
Need to remove asp:Content ID="Content1" runat="server" from the
CustomLogin.aspx
Need to remove DynamicMasterPageFile="~masterurl/default.master" from the
@Page Register tag
Write simple HTML code for the Login Box user interface including username and
password textboxes anda Login Button like below:
5. Step 3:
Add the Microsoft.SharePoint.IdentityModel DLL reference from
.assemblyGAC_MSILMicrosoft.SharePoint.IdentityModel14.0.0.0__71e9bce111e9
429c Microsoft.SharePoint.IdentityModel.dll to access SPClaimsUtility
Include using Microsoft.SharePoint.IdentityModel; at CustomLogin.aspx.cs
Change Inheritance LayoutsPageBase to System.Web.UI.Page
Execute the following code inside the Login button click event as below:
bool status = SPClaimsUtility.AuthenticateFormsUser(
Context.Request.UrlReferrer,
UserName.Text,
Password.Text);
if (!status)// if auth failed
{
lblError.Text = "Wrong Userid or Password";
}
else //if success
{
Response.Redirect("http://fba.contosto.com"); //Use site url
}
Step 4:
Build the solution. Then Deploy the solution package which will create a folder inside .Microsoft
Sharedweb server extensions14TEMPLATELAYOUTSCustomLoginPageFBA
Step 5:
Change the custom page URL using following steps:
6. Go to Central Administration.
Select Site from Application Management.
Click on Authentication Provider.
Select Zone and go inside it to get the following Sign In Page URL Section.
Change Custom Sign In Page URL.
Next Steps
Download the complete source code from here
Check for a future article on how to register a new user for FBA authentication.
Return to MSSharepointTips to read about other topics and ideas.
Check out MSSQLTips.com for great information about Microsoft SQL Server