Vue注册登录及关键项加密

一、规范化API操作

1.1使用Sql Server验证 

1.2使用跨域包进行跨域 在路由页面输入 using web http cors引用

二、上传图片

[HttpPost,Route("api/upload")]
        public IHttpActionResult UpLoad()
        {
            //一、
            //var httpFile = HttpContext.Current.Request.Files[0];
            //var pathService = HttpContext.Current.Server.MapPath("/Images/");
            //httpFile.SaveAs(pathService + httpFile.FileName);
            //return Json(new { url =  httpFile.FileName });
 
            //二、
            //http 协议 Request Response
            //获取文件
            var hpf = HttpContext.Current.Request.Files[0];
            //新名称
            var newFileName = Guid.NewGuid().ToString();
            //获取扩展名
            var ext = Path.GetExtension(hpf.FileName);
            //将文件名和扩展名拼接
            var newName = newFileName + ext;
            //找到路径  将虚拟路径转成物理路径
            var path = HttpContext.Current.Server.MapPath("/Images");
            //合并路径和文件名
            var newPath = Path.Combine(path, newName);
            //保存
            hpf.SaveAs(newPath);
            return Json(new { url=  newName });
 
        }

  

posted @ 2021-09-09 22:13  霜华扶雪  阅读(92)  评论(0)    收藏  举报