Solution for unified logon between Asp. Net Forums and existing Web Systems (:-))

Source: Internet
Author: User

Today, a buddy wants to mount the Asp. Net Forums forum in the system, but does not want to log on to the Forum again outside of the system. This can be considered a single sign-on requirement. It took half a day to get it done, hoping to help friends who have the same requirements.

Now
[2005/04/13]
========================================================== ==============
Asp. Net Forums V2.2.1929 official Chinese Version
========================================================== ==============
The source code is modified as follows:
1) http: // localhost/Forums/Themes/default/Skins/at the View-ForumGroupView.ascx
Users. AutoLogin (); // Add code here
If (Users. GetUser (). IsAnonymous) may be in 10th rows

2) C: \ Inetpub \ wwwroot \ Forum \ Components \ Users. cs
Add the following code:
# Region bigmouthz@163.net 2006.04.17 interface for webpage call

Public static void AutoLogin ()
{
ForumContext forumContext = ForumContext. Current;
If (forumContext. InterFace_user! = Null)
{
User userToLogin = new User ();
UserToLogin. Username = forumContext. InterFace_user;
UserToLogin. Password = forumContext. InterFace_password;
UserToLogin. IPLastLogin = Globals. IPAddress;
UserToLogin. IPLocation = AspNetForums. Components. ipparts. IPLocation (Globals. IPAddress );
UserToLogin. Platform = AspNetForums. Users. GetUsersInfo (forumContext. Context. Request. UserAgent, 1 );
UserToLogin. Browser = AspNetForums. Users. GetUsersInfo (forumContext. Context. Request. UserAgent, 2 );
LoginUserStatus loginStatus = Users. ValidUser (userToLogin, false );
If (loginStatus = LoginUserStatus. Success)
{
// If the system settings Do Not Allow Logon
If (! Globals. GetSiteSettings (). AllowLogin)
{
Bool allowed = false;
Int userid = Users. FindUserByUsername (userToLogin. Username). UserID;
ArrayList roles = Roles. GetRoles (userid );
// If it is an administrator, set allow Login
Foreach (Role role in roles)
{
If (role. Name = "Site Administrators" | role. Name = "Global Administrators ")
{
Allowed = true;
Break;
}
}
// Process User Logon
If (! Allowed)
{
FormsAuthentication. SetAuthCookie (userToLogin. Username, false );
}
}

FormsAuthentication. SetAuthCookie (userToLogin. Username, true );
Forumcontext. Context. response. Cookies [formsauthentication. formscookiename]. expires = datetime. Now. adddays (30 );
}
}

}
# Endregion

3) c: \ Inetpub \ wwwroot \ Forum \ Components \ forumcontext. CS
Add the following content
# Region bigmouthz@163.net 2006.04.17 interface for webpage call
String interface_user = "";
String interface_password = "";
Public String interface_user {get {return interface_user;} set {interface_user = value ;}}
Public String interface_password {get {return interface_password;} set {interface_password = value ;}}
# Endregion

And public forumcontext () in the Method ()
{
Context = httpcontext. Current;

If (context = NULL)
Return;

// Add content

# Region bigmouthz@163.net 2006.04.17 interface for webpage call
Interface_user = context. Request. querystring ["iuser"];
Interface_password = context. Request. querystring ["ipassword"];
# Endregion


..
}

4) In addition, to synchronize the content of your system with the ASP. NET forums User Password table, pay attention to and reference the local code in
Public static LoginUserStatus ValidUser (User user User, bool isRequestFromWebService) of the users. cs class under Components)
 
This is well handled.

5) Call the processing method in the system.
Http: // localhost/Forums/default. aspx? Iuser = admin & ipassword = admin
Pay attentionReplace the input values of iuser and ipassword with the name and password of the current user.

:-)

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.