Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP.net WWG API Membership Wrapper Class
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP.net WWG API Membership Wrapper Class

 Post Reply Post Reply
Author
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Topic: ASP.net WWG API Membership Wrapper Class
    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
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 21 March 2011 at 10:20am
Thanks I'll try that this evening.  It sometimes works, sometimes doesn't at the moment!
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post 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:



Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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 = "/"
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 22 March 2011 at 6:57pm
Excellent!  Seems to work perfectly now, thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.