ASP. NET forums, hereinafter referred to as ANF, version 2.0. In this article, the Coefficient Flow account only records the current work and has no technical content.
The existing system already has its own user system and needs to be mountedANF, Must be registered in the existing system user, login, change the password, inANFThe corresponding response is also made. Not RequiredANFUser changes affect existing systems, but only one-way synchronization.
Try to minimize the number of existingCodeTo complete integration. Previously, I saw the integration solution of cnforums of Baoyu and existing systems. Finally, I was lazy and decided to append the user information and operation type after the above actions of the existing system.URLA new page is sentANF.
This new page is currently calledBridge. aspxOf courseANFInUsingOfUsingIs responsible for receiving user name, password, and other information and then executing the correspondingANFOperation.
- Register
Registration is very simple. My username and password are self-packaged attributes. To obtain information from the request, we can add one without email. Next we need to set accountstatus to pass and isanonymous to turn it off. The bool parameter in users. Create indicates whether to send the email with the registration success prompt to the user. Of course, I disabled the email.
Note that I catch errors everywhere without returning them. You do not have to do this.
Public Void Register ()
{
Try
{
User user = New User ();
User. Username = Username;
User. Password = Password;
User. Email = " Anonymous@Anonymous.com " ;
User. accountstatus = Useraccountstatus. approved;
User. isanonymous = False ;
Users. Create (user, False );
}
Catch
{
}
}
- Login
Basically, it is copied and pasted. Note that the last setcookie is the key to synchronous login.
Public Void Login ()
{
Try
{
User usertologin = New User ();
Usertologin. Username = Username;
Usertologin. Password = Password;
Loginuserstatus loginstatus = Users. validuser (usertologin );
If (Loginstatus = Loginuserstatus. Success)
{
If ( ! Globals. getsitesettings (). allowlogin)
{
Bool Allowed = False ;
Int Userid = Users. finduserbyusername (usertologin. username). userid;
Arraylist roles = Roles. getroles (userid );
Foreach (Role In Roles)
{
If (Role. Name = " Site administrators " | Role. Name = " Global Administrators " )
{< br> allowed = true ;< br> Break ;< BR >}
}
If ( ! Allowed)
{
Return;
}
}
Set_cookie (usertologin. username, " 1 " );
}
}
Catch
{
}
}
- Change Password
This assumption is based on the fact that the logon has occurred. If this is not the case, you need to add your own judgment.
Public Void Changepassword ()
{
Try
{
Forumcontext = Forumcontext. Current;
User user = Forumcontext. user;
If (User ! = Null )
{
User. changepassword (password, newpassword );
}
}
Catch
{
}
}
Public Void Set_cookie ( String Username, String Selet_item)
{
If (Selet_item = " 0 " )
{
Formsauthentication. setauthcookie (username,False);
}
Else
{< br> forumcontext = forumcontext. current;
formsauthentication. setauthcookie (username, true );
forumcontext. context. response. cookies [formsauthentication. formscookiename]. expires = datetime. now. adddays (system. convert. toint32 (selet_item);
}
}
Finally, register with the existing system, log on, and modify the last response. redirect page. If you do not like redirect, server. Transfer, and XMLHTTP, you can see what you need. Another key point is to encrypt the character string you transmitted, or use plain text ...... ※¥ ※×% ※× If it is not secure, use an IP address to determine who can access this page!