﻿using System;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Collections.Generic;

using GoodStudy.Core;
using GoodStudy.Services;

namespace GoodStudy.Web.Framework
{
    /// <summary>
    /// PC前台基础控制器类
    /// </summary>
    public class BaseWebController : BaseController
    {
        //工作上下文
        public WebWorkContext WorkContext = new WebWorkContext();

        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;
            WorkContext.IP = WebHelper.GetIP();
            WorkContext.IsHttpAjax = WebHelper.IsAjax();
            WorkContext.Url = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();
            //获得用户唯一标示符sid
            WorkContext.Sid = PlatformUtils.GetSidCookie();

            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                PlatformUtils.SetSidCookie(WorkContext.Sid);
            }
        }

        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            
        }

        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }
    }
}
