NetMVC sets up Ucenter synchronous login and exits discuz, netmvcucenter

Source: Internet
Author: User

NetMVC sets up Ucenter synchronous login and exits discuz, netmvcucenter

First look at the effect

First, prepare materials:

1. ucenter for net: https://github.com/dozer47528/UCenter-API-For-DotNet or http://pan.baidu.com/s/1i3znQV7

2. The specific code below uc. ashx

Using DS. web. UCenter; using DS. web. UCenter. api; using DS. web. UCenter. client; using log4net; using pc_manishi.Controllers; using System. collections. generic; using System. linq; using System. web; namespace pc_manishi.API {// <summary> // Summary description for uc /// </summary> public class uc: UcApiBase {HttpResponse Response = HttpContext. current. response; HttpRequest Request = HttpContext. current. request; private static readonly ILog logger = LogManager. getLogger (typeof (AddressController); public override ApiReturn DeleteUser (IEnumerable <int> ids) {throw new NotImplementedException ();} public override ApiReturn RenameUser (int uid, string oldUserName, string newUserName) {throw new NotImplementedException ();} public override UcTagReturns GetTag (string tagName) {throw new Login ();} // log on to public override ApiReturn SynLogin (int uid) {try {IUcClient client = new UcClient (); UcUserInfo user = client. userInfo (uid); if (user. success) {// LoggerCore. debug (user. uid + "--" + user. userName); HttpContext. current. session ["uid"] = user. uid; HttpContext. current. session ["username"] = user. userName; HttpContext. current. session ["email"] = user. mail; return ApiReturn. success;} return ApiReturn. failed;} catch (Exception ex) {logger. error ("remote logon Error", ex); return ApiReturn. failed;} // throw new NotImplementedException ();} // log out public override ApiReturn SynLogout () {try {logger. error ("the forum is being logged out"); // HttpContext. current. session. abandon ();} catch (Exception ex) {logger. error ("remote exit Error", ex);} return ApiReturn. success; // throw new NotImplementedException ();} public override ApiReturn UpdatePw (string userName, string passWord) {throw new reset ();} public override ApiReturn UpdateBadWords (UcBadWords badWords) {throw new handle ();} public override ApiReturn UpdateHosts (UcHosts hosts) {throw new handle ();} public override ApiReturn UpdateApps (UcApps apps) {throw new NotImplementedException ();} public override ApiReturn UpdateClient (UcClientSetting client) {throw new NotImplementedException ();} public override ApiReturn UpdateCredit (int uid, int credit, int amount) {throw new charge ();} public override UcCreditSettingReturns GetCreditSettings () {throw new NotImplementedException ();} public override ApiReturn GetCredit (int uid, int credit) {throw new NotImplementedException ();} public override ApiReturn UpdateCreditSettings (UcCreditSettings creditSettings) {throw new NotImplementedException ();}}}

Let's start:

First, create the uc. ashx file in the resume api folder of your mvc project.

When creating the ashx file, you must pay attention to the namespace. The generated project is different from the current one, but the compilation is successful. I found this place wrong after debugging for a long time.

Configure the webconfig file and add the following configurations (depending on your situation)

<! -- Client Version --> <add key = "UC_CLIENT_VERSION" value = "1.6.0"/> <! -- Release date -- & gt; <add key = "UC_CLIENT_RELEASE" value = "20141101"/> <! -- API switch (value Type: True False default value: True) --> <! -- Whether users can be deleted --> <add key = "API_DELETEUSER" value = "True"/> <! -- Whether to rename a user --> <add key = "API_RENAMEUSER" value = "True"/> <! -- Whether to obtain tags --> <add key = "API_GETTAG" value = "True"/> <! -- Allow synchronous logon? --> <add key = "API_SYNLOGIN" value = "True"/> <! -- Whether to allow synchronous logout --> <add key = "API_SYNLOGOUT" value = "True"/> <! -- Allow password change --> <add key = "API_UPDATEPW" value = "True"/> <! -- Whether to allow keyword update --> <add key = "API_UPDATEBADWORDS" value = "True"/> <! -- Whether domain name resolution cache can be updated --> <add key = "API_UPDATEHOSTS" value = "True"/> <! -- Allow update of Application List --> <add key = "API_UPDATEAPPS" value = "True"/> <! -- Allow update of Client Cache --> <add key = "API_UPDATECLIENT" value = "True"/> <! -- Allow updating user credits --> <add key = "API_UPDATECREDIT" value = "True"/> <! -- Whether to enable point settings for UCenter --> <add key = "API_GETCREDITSETTINGS" value = "True"/> <! -- Whether to allow the user to obtain a certain point --> <add key = "API_GETCREDIT" value = "True"/> <! -- Allow update of application credit settings --> <add key = "API_UPDATECREDITSETTINGS" value = "True"/> <! -- The API switch ends --> <! -- Return Value Setting --> <! -- Return success (default: 1) --> <add key = "API_RETURN_SUCCEED" value = "1"/> <! -- Return failure (default:-1) --> <add key = "API_RETURN_FAILED" value = "-1"/> <! -- Return disabled (default:-2) --> <add key = "API_RETURN_FORBIDDEN" value = "-2"/> <! -- End of Return Value Setting --> <! -- [Required] Communication key --> <add key = "UC_KEY" value = "20150612"/> <! -- [Required] UCenter address --> <add key = "UC_API" value =" http://XXX/uc_server "/> <! -- [Required] default encoding --> <add key = "UC_CHARSET" value = "UTF-8"/> <! -- [Optional] UCenter IP --> <add key = "UC_IP" value = ""/> <! -- [Required] Application ID --> <add key = "UC_APPID" value = "2"/>
UC_KEY, UC_API, and UC_APPID are required. You must change them to the net website configuration you have added.


Next we look forward to a successful communication. If the communication fails, check the configuration of config_ucenter.php in discuz and the webconfig of the website.
Discuz! The Board will usually communicate successfully, because I also installed ucenter together when installing discuz. Unless you have migrated the website, I will discuss the problems after the migration.

The next step is synchronous login:
Here is my code

Actually, the IUcClient class method is called, and then the remote login js Code is obtained through usersynlogin. I don't know why, I use Response. write () to output to the front end, but here I return to xmlHttpResponse, which is not available in html
So here I used webhttprequest for processing. The principle is that there is a src in the returned js. You can access the cookie directly in the browser, however, note that the second-level domain name sharing should be set for the cookie domain name, and the same process should be done if the cookie is exited.

Let's talk about registration: I disabled the verification code here and removed the required email address (du Niang can tell you how to close it)
Client. UserRegister (username, Password, string. Format ("{0: ddhhmmss}", DateTime. Now) + "@ suiji.com", 0, "") is also called directly below ,"");
If you remove the required email address in time, you also need to give a default email address. Here I randomly generate a mailbox


Note that even if you enable the function, activate it immediately.
You also need to log in to make discuz automatically activate your user

Next, let's talk about the migration precautions (I moved from winserver to linux ):
1: The domain name of the url cookie in the configuration must be changed.
2. Do not use notepad when using ftp for modification. This will cause Encoding Problems and cause communication failure.
3. 777 permissions for these folders and files, such as data source template (check the file permissions if something goes wrong)


The article is not very detailed. Sorry for the question.
Thanks:
UCenter API For. Net is released on CodePlex!

Colleagues in the company's php and linux
 

  

 

Related Article

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.