示例#1
0
        public JwtToken Decode(string tokenStr)
        {
            string[] parts = tokenStr.Split(".");

            var header  = SerializeExt.JsonTo <JwtHeader>(EncodingExt.FromBase64Url(parts[0], null));
            var payload = SerializeExt.JsonTo <JwtPayload>(EncodingExt.FromBase64Url(parts[1], null));

            return(new JwtToken
            {
                Header = header,
                Payload = payload
            });
        }
示例#2
0
        public static object GetValue(this Request requset, string name, Type type)
        {
            if (type != typeof(string) && type.IsClass)
            {
                return(requset.GetObject(name, type));
            }

            string value = requset.Form[name];

            if (value == null)
            {
                value = requset.Query[name];
            }
            if (value == null)
            {
                throw new Exception("不能获取名称为" + name + "的值");
            }

            if (type == typeof(string) ||
                type == typeof(char) ||
                type == typeof(bool) ||
                type == typeof(byte) ||
                type == typeof(short) ||
                type == typeof(int) ||
                type == typeof(uint) ||
                type == typeof(long) ||
                type == typeof(ulong) ||
                type == typeof(float) ||
                type == typeof(double) ||
                type == typeof(decimal) ||
                type == typeof(Guid) ||
                type == typeof(DateTime))
            {
                return(TypeExt.ConvertType(type, value));
            }

            return(SerializeExt.JsonTo(value, type));
        }