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.
:-)