Print Page | Close Window

ASP.net WWG API Membership Wrapper Class

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums Modifications
Forum Description: Mod's and Add-on's for Web Wiz Forums.
URL: https://forums.webwiz.net/forum_posts.asp?TID=29192
Printed Date: 29 March 2026 at 6:49pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ASP.net WWG API Membership Wrapper Class
Posted By: Gullanian
Subject: ASP.net WWG API Membership Wrapper Class
Date Posted: 19 March 2011 at 7:31pm
This is an ASP.net c# wrapper class designed for you to integrate your website easily with Web Wizs forum easily.

The only issue at the moment is with the cookies, they seem to work intermitetly when calling the login function.  I think it has something to do with paths, if anyone can work this out for me it would be great :)

Usage

Makes integration with membership easy.  Use like follows:
        // Create a new user and print out some of their details
        ForumAPI.WebWizUserDetails me = ForumAPI.NewUser("NewUser", "Password", true);
        Response.Write(me.Username);
        Response.Write(me.Posts);
        Response.Write(me.JoinDate);

        // Load user by username.  Also can do it by ID or XML data
        ForumAPI.WebWizUserDetails SomeUser = new ForumAPI.WebWizUserDetails("NewUser");

        // Suspend them
        SomeUser.Suspend();

        // Unsuspend
        SomeUser.Unsuspend();

        // Load their cookie data
        SomeUser.GetCookieData();

        // Login with this cookie data which expires in 10 mins
        SomeUser.CookieData.LoadCookie((double)10);

        // Login with this cookie data which expires in 10 days
        SomeUser.CookieData.LoadCookie((int)10);

There's a lot more functions in there, browse the code to see.  It's commented for intellisense to make it easy to use.

Notes

This isn't thoroughly tested, there isn't much error checking going on, so use at your own risk.  It's a work in progress for my website, if I ever update it significantly I'll try and post it in here.

Installation

You need to add the following keys to your <appSettings> in your web.config:
<add key="AdminUsername" value="Administrator"/>
<add key="AdminPassword" value="letmein"/>
<add key="ForumAPILocation" value="http://localhost/ScirraNew/forum/HttpAPI.asp"/>

Then create a new class in your App_Code folder called ForumAPI.cs.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Configuration;
using System.Xml;

/// <summary>
/// ASP.net Wrapper for the WebWizAPI V1.0
/// (c) Thomas Gullen, 2011 
/// http://www.Scirra.com
/// 
/// Free to use as long as this
/// copyright information remains unedited.
/// Distribution prohibited without authorisation
/// from Scirra.com
/// </summary>
/// 
/// TODO:
/// CreateMember

public class ForumAPI
{
    /// <summary>
    /// The date format parameter for web wi
    /// </summary>
    public static class WebWizDateFormat
    {
        public const string USFormat = "mm/dd/yy";
        public const string UKFormat = "dd/mm/yy";
        public const string YYDDMMFormat = "yy/dd/mm";
        public const string YYMMDDFormat = "yy/mm/dd";
    }

    /// <summary>
    /// Cookie information for a user
    /// </summary>
    public class WebWizCookie
    {
        public string Username { get; set; }
        public int UserID { get; set; }
        public string CookieName { get; set; }
        public string CookieKey { get; set; }
        public string CookieData { get; set; }
        public string CookiePath { get; set; }
        public string ForumPath { get; set; }

        /// <summary>
        /// Loads cookie data
        /// </summary>
        /// <param name="Username">Username to load cookie data for</param>
        public WebWizCookie(string Username)
        {
            GetCookieByUsername(Username);
        }

        /// <summary>
        /// Turns cookie data into actual ASP.net cookie
        /// </summary>
        /// <param name="MinutesExpiry">Minutes in the future this cookie will expire</param>
        public void LoadCookie(double MinutesExpiry)
        {
            CookieDataToCookie(DateTime.Now.AddMinutes(MinutesExpiry));
        }
        /// <summary>
        /// Turns cookie data into actual ASP.net cookie
        /// </summary>
        /// <param name="MinutesExpiry">Minutes in the future this cookie will expire</param>
        public void LoadCookie(int DaysExpiry)
        {
            CookieDataToCookie(DateTime.Now.AddDays(DaysExpiry));
        }
        /// <summary>
        /// Turns cookie data into actual ASP.net cookie
        /// </summary>
        /// <param name="MinutesExpiry">Datetime this cookie will expire</param>
        public void LoadCookie(DateTime ExpiryDate)
        {
            CookieDataToCookie(ExpiryDate);
        }
        private void CookieDataToCookie(DateTime Expiry)
        {
            HttpContext.Curr



Replies:
Posted By: WebWiz-Bruce
Date Posted: 21 March 2011 at 7:53am
Very nice Smile 

In regards to your cookie question, Web Wiz Forums sets cookies to the forums own root directory. If you are setting cookies on other parts of your site for the forum you need to edit the includes/setup_options_inc.asp file in notepad and change the cookie path to the websites root so that cookies set outside the forums root directory can be read.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: Gullanian
Date Posted: 21 March 2011 at 10:20am
Thanks I'll try that this evening.  It sometimes works, sometimes doesn't at the moment!


Posted By: Gullanian
Date Posted: 21 March 2011 at 6:42pm
I've changed the cookie path to:

strCookiePath = "http://127.0.0.1/"

But it's still setting cookies to the http://127.0.0.1/ScirraNew/Forum path, which causes the cookie to sometimes work sometimes not Confused

Here's a snap shot of cookie state on the site in it's 3 possible states:

http://img716.imageshack.us/img716/667/cookiesa.gif" rel="nofollow - http://img716.imageshack.us/img716/667/cookiesa.gif




Posted By: WebWiz-Bruce
Date Posted: 22 March 2011 at 12:12pm
set the cookie path to the root using just / as the cookie path. You should not need a domain.:-

strCookiePath = "/"


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: Gullanian
Date Posted: 22 March 2011 at 6:57pm
Excellent!  Seems to work perfectly now, thanks!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net