Vue3 从入门到实战 进阶式掌握完整知识体系

download:Vue3 从入门到实战 进阶式掌握完整知识体系

谁说为0基础准备的课,就一定浅薄?本课程带你轻松入门、深度掌握 Vue3,夯实前端硬技能。课程从 Vue3 基础语法,到组件原理,动画,代码设计,再到新语法扩展,由浅入深,全面、系统地梳理 Vue 知识点。在学习过程中,还有老师多年的“避坑经验”倾囊相授 ,并在最后带你按照企业级别代码质量和工程开发流程完成“京东到家”应用,实现对框架的彻底掌握。

适合人群
想要从零开始彻底入门 Vue 的同学;
想要了解清楚 Vue3 原理和新语法的同学;
希望扩展前端知识面,寻求升职加薪机会的同学
技术储备要求
熟悉JS基础语法;
了解Npm开发环境;
了解Webpack基本操作
登錄的逻輯應該是
session中存儲用戶的主要信息
key:guid類型
value: 用戶的信息
cookie中存儲效勞端的session的數據類型
key:CurrentUser //這是一個固定的值
value: session中的key的名字

  1. 相關代码如下:

登錄控製器

//這是一個空過濾過濾器,表示該控製器里的都不停止過濾
[CustomAllowAnonymous]
public class SessionLoginController : Controller
{
[HttpGet]
public IActionResult SessionLogins(int a)
{
if (a == 1)
{
#region Cookie/Session 本人寫 普通運用Sessio爲主
CurrentUser currentUser = new CurrentUser()
{
Id = 123,
Name = "wangjin",
Account = "Administrator",
Email = "1293604064",
Password = "123456",
LoginTime = DateTime.Now
};
//生成一個guid的值用來存儲主键的值
Guid sessionKey = Guid.NewGuid();
//寫Session/寫Cookies
base.HttpContext.SetCookies("CurrentUser", sessionKey.ToString(), 30);
//寫入session
base.HttpContext.Session.SetString(sessionKey.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(currentUser));
#endregion
return base.Redirect("/Home/Index");
}
return View();
}
}
辦法過濾器

///

/// 辦法過濾器
/// 
public class CustomActionFilterAttribute : Attribute, IActionFilter
{
    /// 

    /// 辦法執行前
    /// 
    /// 
    public void OnActionExecuting(ActionExecutingContext context)
    {
        //表示假如帶有該屬性,就不停止下面的步骤,直接返回
        if (context.ActionDescriptor.EndpointMetadata.Any(item => item.GetType() == typeof(CustomAllowAnonymousAttribute))) //假如標誌的有特殊的記號,就避開檢查;
        {
            return;
        }
        Byte[] bytes;
        context.HttpContext.Session.TryGetValue("CurrentUser", out bytes);
        string cookieKey = CookieSessionHelper.GetCookiesValue(context.HttpContext, "CurrentUser");
        string str = cookieKey != null ? new SessionHelper(context.HttpContext).GetSession(cookieKey) : null;
        if (string.IsNullOrEmpty(str))
        {
            var result = new ViewResult { ViewName = "~/Views/SessionLogin/SessionLogins.cshtml" };
            //result.ViewData = new ViewDataDictionary(_modelMetadataProvider, context.ModelState);
            //result.ViewData.Add("Exception", context.Exception);
            context.Result = result; //斷路器---只需對Result赋值--就不繼續往後了;
        }
        Console.WriteLine("這是辦法執行前");
    }
    /// 

    /// 辦法執行後
    /// 
    /// 
    public void OnActionExecuted(ActionExecutedContext context)
    {
        if (context.ActionDescriptor.EndpointMetadata.Any(item => item.GetType() == typeof(CustomAllowAnonymousAttribute))) //假如標誌的有特殊的記號,就避開檢查;
        {
            return;
        }
        Console.WriteLine("這是辦法執行後");
    }
}

空白過濾器,目的是爲了跳過過濾器

public class CustomAllowAnonymousAttribute:Attribute
{
}
在ConfigureServices中添加如下:

services.AddSession();
services.AddMvc(option =>
{
option.Filters.Add(); //全局注册:
option.Filters.Add(); //全局注册異常過濾器:
});
在Configure中添加如下:

        app.UseSession();
app.UseCookiePolicy();
還有操作cookie封裝的辦法:

public static class CookieSessionHelper
{
public static void SetCookies(this HttpContext httpContext, string key, string value, int minutes = 30)
{
httpContext.Response.Cookies.Append(key, value, new CookieOptions
{
Expires = DateTime.Now.AddMinutes(minutes)
});
}
public static void DeleteCookies(this HttpContext httpContext, string key)
{
httpContext.Response.Cookies.Delete(key);
}
public static string GetCookiesValue(this HttpContext httpContext, string key)
{
httpContext.Request.Cookies.TryGetValue(key, out string value);
return value;
}
public static CurrentUser GetCurrentUserBySession(this HttpContext context)
{
string sUser = context.Session.GetString("CurrentUser");
if (sUser == null)
{
return null;
}
else
{
CurrentUser currentUser = Newtonsoft.Json.JsonConvert.DeserializeObject(sUser);
return currentUser;
}
}
}
封裝操作Session的

public class SessionHelper
{
private IHttpContextAccessor _accessor;
private ISession _session;
private IRequestCookieCollection _requestCookie;
private IResponseCookies _responseCookie;
public SessionHelper(HttpContext context)
{
_session = context.Session;
_requestCookie = context.Request.Cookies;
_responseCookie = context.Response.Cookies;
}
///

    /// 設置session值
    /// 
    /// 
    /// 键
    /// 值
    public void SetSession(string key, string value)
    {
        var bytes = System.Text.Encoding.UTF8.GetBytes(value);
        _session.Set(key, bytes);
    }
    /// 

    /// 獲取Session值
    /// 
    /// 
    /// 
    public string GetSession(string key)
    {
        Byte[] bytes;
        _session.TryGetValue(key, out bytes);
        var value = System.Text.Encoding.UTF8.GetString(bytes);
        if (string.IsNullOrEmpty(value))
        {
            value = string.Empty;
        }
        return value;
    }
    ///// 

    ///// 設置本地cookie
    ///// 
    ///// 键
    ///// 值
    ///// 過時時間
    //public void SetCookies(string key,string value,int day = 1)
    //{
    //    _responseCookie.Append(key, value, new CookieOptions
    //    {
    //        Expires = DateTime.Now.AddDays(day)
    //    }) ;
    //}
    //public void  DeleteCookies(string key)
    //{
    //    _responseCookie.Delete(key);
    //}
    //public string GetCookiesValue(string key)
    //{
    //    _requestCookie.TryGetValue(key, out string value);
    //    if (string.IsNullOrEmpty(value))
    //    {
    //        value = string.Empty;
    //    }
    //    return value;
    //}
}
上一篇:HttpContext.Current.Session.Abandon() 大坑 要注意


下一篇:HttpContext.Current.Request空指针异常(NullPointerException)