Moss-custom membershipprovider-implement forms verification-learning practices

Source: Internet
Author: User

Some time ago, in order to implement forms verification using a custom membershipprovder in Moss, I read a lot of blog posts and spent a lot of time. Now I have succeeded. (With a sigh of relief, you may have a little sense of accomplishment. Although it was made by referring to others' tutorials, you may not laugh when you get yourself started :).) The following is a summary of the entire implementation process. Before that, of course, we would like to thank our colleagues who provided similar tutorials. Because of your selflessness, the younger brother has made fewer detours on the way forward, and the younger brother bowed to you! (There are so many reference articles that I can't list them here. If I see them in my peers, I feel like I have never known each other. I hope I can laugh at them. I don't want to throw rotten eggs or bad cabbage! Haha)

No nonsense. Start text:

Bytes -------------------------------------------------------------------------------------------------------------

Software environment:

1. Window srver 2003 sp2

2. iis6.0

3. asp. net2.0

4. sharepoint2007 Chinese Version

5. SQL Server 2005

6. vs2005/vs2008

After Sharepoint is installed, open IIS and you will find that "SharePoint Central Administration V3" and "SharePoint 80" are added to the "application pool" and "website. Click "default website"-> "WSS"-> "virtualdirectories", and you will find that there are two more folders: "80" and "35117" (each of them will be different. You can find these two folders in the directory address "C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories. "35117" is the Management Center site, and "80" is the site created by default when Sharepoint is installed.

Right-click "website"-> "SharePoint Central Administration V3"-> "all tasks"-> "SharePoint Management Center" To Go To The SharePoint Management Center website. (You can also go to "start"> "program"> "Management Tools"> "SharePoint 3.0 Management Center)

Create a Sharepoint website

Go to the sharepint management center, select "Application Management", and click "create or expand web application" under the "SharePoint Web Application Management" directory ". Select "Create web application", modify the port number such as 9000, select allow anonymous access, enter the application pool to configure the account and password (domain administrator account), and select the default value for other options, click "OK" to create a web application. (After successful creation, we will find that the "SharePoint 9000" folder is added to the "application pool" and "website" in IIS. In the same way, "9000" is added to "default website"> "WSS"> "virtualdirectories .) Click "create website set" in the "Success prompt". (You can also go back to Application Management in the management center and click "create website set" under the "SharePoint website management" directory ") go to the create website set page. Enter the title, URL path (default), and template, enter the website set primary Administrator (domain administrator account), and click OK. After the website is created, copy the URL of the website set to open it in the new browser. Enter the Administrator account and password of the website set to view the website we just created. The current authentication method for Sharepoint 9000 applications is Windows authentication, which is also the default verification method for creating applications. In the management center-> Application Management-> application security, click "verify the provider" under the "Application Security" directory, and change "Web application" in the upper right corner to 9000 we just created. The membership provider is "Windows ". Click "default" to go to the "Edit Verification" page. We can see that the verification type is "Windows", and there are two verification methods available: "form" and "Web Single login. What we need to achieve is to select "form" for verification and use the custom "membership provider ". This part is coming to an end. You can put it aside first.

Implement a custom membership verification program

Create a class library project "myprovider", create a class "mymembershipprovider", inherit the abstract class "membershipprover", and override the method of the parent class.

The main rewrite method is as follows:

Public override bool validateuser (string username, string password );

Public override membershipusercollection findusersbyname (string usernametomatch, int pageindex, int pagesize, out int totalrecords );

Public override membershipuser getuser (string username, bool userisonline );

Public override membershipuser getuser (Object provideruserkey, bool userisonline );

Other methods can be implemented based on your needs.

Of course, it is best to create a new Web application and use the custom membership provider for forms verification testing to ensure that your implementation is correct.

Note: You must generate a strongly-named assembly for this class library. Otherwise, the error "type cannot be loaded..." may occur during external calls. How to strongly name an assembly)

Configure the moss website to use the custom membershipprover for Forms authentication

Go to "Management Center"-> "Application Management"-> "verify the provider"-> select an application whose web application is port 9000-> click "default" -> go to the edit verification page, select the authentication method as "forms", select "enable Anonymous Access", and enter the name of the member identity Provider, for example, mymembershipprover (you can do it at will, note that it should be consistent with the name in the subsequent configuration file) click OK.

A. Copy the strongly-named Assembly myprovider. dll generated in the previous section to the bin directory of application 9000 and Management Center site (35117.

(Path: "C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories ")

B. Add myprovider. DLL to GAC. How to add an assembly (. dll file) to GAC (Global Assembly Cache )?

C. Modify the Web. config configuration file of the application 9000 site (under "C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 9000 ):

Add the following code to the <configuration> node:

<Connectionstrings>
<Add name = "connectionstring" connectionstring = "database server; uid = sa; Pwd = sa; database = Database"/>
</Connectionstrings>

Add the following code under the <system. Web> node: (The defaultprovider name must be the same as that configured on the front)

<Membership defaultprovider = "mymembershipprovider">
<Providers>
<Clear/>
<Add connectionstringname = "myconnectionstring" applicationname = "/" name = "mymembershipprovider" type = "myprovider. mymembershipprovider, myprovider, version = 1.0.0.0, culture = neutral, publickeytoken = credential"/>

</Providers>
</Membership>

Description of type content: 1. namespace. Class Name; 2. Minzhu space; 3. Version Number; 4. region; 5. Public Key of Strongly-named assembly

D. Modify the Web. config configuration file of the Management Center site (under "C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 35117 ):

The modified content is the same as that on the same side.

Note that you must change the level in <trust level = "wss_minimal" originurl = ""/> to "full ".

E. Restart IIS (START-run (CTRL + r)-> iisreset)

F. go to "Management Center"-> "Application Management"-> "website set administrator->" website set "select the website set under the application whose port number is 9000-> we found that the original the primary administrator of the website set prompts "the project cannot be exactly matched ", this is because after we change to form verification, we will use the custom membershipprover we set to query the database we connect to determine whether the user exists. This is an existing user in the database. Click Save. Access the website set address of site 9000 again, enter an existing user in our database and click log on. The system prompts that the current logon user is XX, but the website set cannot be accessed, this is because we did not assign this user the permission to access the website set.

Choose "Management Center"> "Application Management"> "Web application policy"> "Add User", click Next, and enter a valid user in the database, select "full control" and click "finish ". In this case, access the newly created application set again, enter the user name and password with full control permissions in the application policy, and click log on to access the changed website set. Click "personnel and group"-> "new"-> "Add User" To Go To The add user interface. In the input box, enter the usernames in the database (multiple users can be separated by semicolons ), select directly assign user permissions, select permissions such as "read View", and click OK. Click the "Welcome xx" drop-down box in the upper-right corner of the website and select "Log on as another user". Return to the logon page and log on with the user we just created, you will find that you have been able to access the website (of course, only the viewing permission is required ).

This is the end of my introduction. I hope it will help you. It is also a summary of my learning achievements in recent days!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.