ASP. NET site integration discuz forum for Synchronous registration and single sign-on

Source: Internet
Author: User

Recently, we integrated the discuz forum in a small site. After reading some documents, we achieved synchronous registration and single-point login. Discuz loads the website as a virtual directory and integrates discuz into the website. Pay attention to the following issues:

  • In the directory where discuz is located, you must add the permissions of the network service and iis_user accounts.
  • DNT in the root directory of discuz. to modify the config file, change <forumpath>/</forumpath> to <forumpath>/BBS/</forumpath>. BBS is the name of the virtual directory.
  • Because my website uses a third-party control, related settings are made in the webconfig file, and the system prompts a lack of Assembly reference when accessing the Forum, later, the third-party control DLL is added to the bin directory under discuz.

Next, let's talk about how to implement synchronous registration and single-point logon. After the research, I found it very simple. Of course, I am only working on the same domain, and I have not studied cross-domain situations, it is estimated that it will not be very difficult. It should be an additional process for setting cookiedomain. Discuz provides us with a discuztoolkit and provides many APIs for calling. Next, let's take a step. 1. After the discuz forum is installed, go to the background management and choose "extend"> "Pass Settings"> "add integration program settings ".

  • Application name: Enter
  • Application URL: I entered the address of my site
  • Return address after Logon: Same as above

2. Write down the generated apikey and key, which will be used in subsequent code writing.

3. I have configured the apikey and key in the webconfig file.

  • Apikey: the value of the value is the apikey generated in the background.
  • Secret: The value is the secret key generated in the background.
  • URL: path where the value is BBS

4. Write a public bbshelper class that encapsulates methods such as adding users, logging in, and changing passwords. Note that the namespace discuz. Toolkit must be referenced.

/// <Summary> /// synchronize the discuz forum help class /// </Summary> public class discuzbbshelper {private string _ apikey = string. empty; private string _ secret = string. empty; private string _ url = string. empty; discuzsession _ DS; Public discuzbbshelper () {_ apikey = confighelper. apikey (); _ secret = confighelper. secret (); _ url = confighelper. URL (); _ DS = new discuzsession (_ apikey, _ secret, _ URL );} /// <summary> /// log on /// </Summary> Public void login (string username, string PWD) {int uid = _ DS. getuserid (username); _ DS. login (UID, PWD, false, 100, "") ;}/// <summary> /// logout /// </Summary> Public void logout () {_ DS. logout (""); _ DS. session_info = NULL; httpcontext. current. session ["authtoken"] = NULL;} // <summary> // create a user /// </Summary> Public void adduser (string username, string PWD) {_ DS. register (username, PWD, "", false) ;}/// <summary >/// change the password /// </Summary> Public void changepwd (string username, string oldpwd, string newpwd) {int uid = _ DS. getuserid (username); _ DS. changeuserpassword (UID, oldpwd, newpwd, newpwd ,"");}}

5. Call the method in this class as required by the website, as shown below:

// Synchronize Forum discuzbbshelper BBS = new discuzbbshelper (); bbs. login (username, PWD );
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.