public ControllerBase(IOptions <WebSettings> webSettings, IValidateCode validateCode, HttpContextExtension httpExtension, ICMSAdminBO cmsAdminBO, ICMSAdminCookie cmsAdminCookie) { WebSettings = webSettings; ValidateCode = validateCode; HttpExtension = httpExtension; CMSAdminBO = cmsAdminBO; CMSAdminCookie = cmsAdminCookie; }
public CMSAdminCookie(IOptions <WebSettings> webSettings, HttpContextExtension httpExtension) { WebSettings = webSettings; HttpExtension = httpExtension; }
/// <summary> /// 实现页面内容的输出(采用异步IO读取) /// </summary> /// <param name="ashxRoute">当前请求对象</param> /// <returns></returns> public override async Task ExecuteOutAsync(AshxRouteData ashxRoute) { Microsoft.AspNetCore.Hosting.IWebHostEnvironment env = ashxRoute.HttpContext.GetService <Microsoft.AspNetCore.Hosting.IWebHostEnvironment>(); Microsoft.Extensions.FileProviders.IFileInfo view; if (env.WebRootPath is null) { string webRootPath = env.ContentRootPath + "\\wwwroot"; System.IO.Directory.CreateDirectory(webRootPath + "\\Views"); env.WebRootPath = webRootPath; env.WebRootFileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(webRootPath); } //string filePath = ""; if (IsView) { //string directory = AppContext.BaseDirectory; //filePath = string.Concat(directory, "ApiView\\", ashxRoute.Controller, '\\', ashxRoute.Action, ".html"); if (string.IsNullOrEmpty(ViewName)) { ViewName = $"Views\\{ashxRoute.Controller}\\{ashxRoute.Action}.html"; } else { ViewName = $"Views\\{ashxRoute.Controller}\\{ViewName}\\{ashxRoute.Action}.html"; } view = env.WebRootFileProvider.GetFileInfo(ViewName); } else { view = env.WebRootFileProvider.GetFileInfo(ViewName); //if (ViewName != null && ViewName[1].Equals(':')) //{ // filePath = ViewName; //} //else //{ // string directory = AppContext.BaseDirectory; // filePath = string.Concat(directory, ViewName);// '\\' $"{directory}/{ViewName}"; //} //System.IO.File.Exists(@"D:\Nixue工作室\Tool.Net\WebTestApp\wwwroot\"+ViewName); //System.IO.File.OpenRead(@"D:\Nixue工作室\Tool.Net\WebTestApp\wwwroot\" + ViewName); } //if (System.IO.File.Exists(filePath)) //{ // filePath = viewName; //} //else //{ // string directory = AppContext.BaseDirectory.Replace("\\", "/"); // filePath = $"{directory}/{viewName}"; //} if (view.Exists) { //byte[] obj = System.IO.File.ReadAllBytes(filePath); //byte[] obj = await System.IO.File.ReadAllBytesAsync(filePath); //await ashxRoute.HttpContext.Response.WriteAsync(obj); System.IO.Stream streamview = view.CreateReadStream(); System.IO.Stream writeStream = ashxRoute.HttpContext.Response.Body; //long len = (1024 * 50) > view.Length ? view.Length : (1024 * 50); //byte[] slice = new byte[len]; //long seekiength = 0; //do //{ // int i = await streamview.ReadAsync(slice.AsMemory(0, slice.Length)); // await writeStream.WriteAsync(slice.AsMemory(0, i)); // await writeStream.FlushAsync(); // seekiength += i; // Array.Clear(slice, 0, i); //} while (view.Length > seekiength); //await streamview.DisposeAsync(); await HttpContextExtension.StreamMove(streamview, writeStream, 1024 * 50); } else { throw new Exception("找不到页面:“(相对路径)wwwroot\\" + ViewName + "”,无法显示!"); } }
public IActionResult AddSysUser([FromBody] FromAddSysUser model) { string code = "000000"; var user = AutoMapperExt.MapTo <Sys_User>(model); user.Password = Encrypt.EncryptPsw(user.Password); Log_Admin logAdmin = new Log_Admin(); var now = DateTime.Now; if (_sysUserService.IsAny(p => p.UserName == user.UserName)) { return(ReturnJson("100001")); } else { user.LastIp = HttpContextExtension.GetIp(HttpContext); user.LastLogDate = now; user.CrtUser = GetJwtIEntity().Name; user.CrtDate = now; user.Id = _sysUserService.Insert(user, false); if (user.Id > 0 && !string.IsNullOrEmpty(user.HeadImgUrl)) { //更改图片状态 _sysUploadService.UpdateUploadStatusAsync(UploadTypeEnum.image, user.HeadImgUrl, UploadStatusEnum.使用中); } if (user.Id > 0 && model.RoleList.Count > 0) { //异步执行角色权限配置 Task.Run(() => { var perList = new List <Sys_UserRole>(); foreach (var item in model.RoleList) { var perModel = new Sys_UserRole(); perModel.RoleId = item.RoleId; perModel.UserId = user.Id; perList.Add(perModel); } _sysUserService.InsertList(perList); }); } else if (user.Id == 0) { code = "000001"; } logAdmin.Remark = "账号:" + user.UserName + "注册成功"; logAdmin.TypeId = (int)EnumLogAdminType.add_sysUser;//添加用户时的类型Id } logAdmin.OtherId = user.Id.ToString(); logAdmin.CrtUserId = GetJwtIEntity().UserId; logAdmin.CrtUserName = GetJwtIEntity().Name; _logAdmin.LogAdmin(logAdmin, HttpContext); return(ReturnJson(code)); }
public LoginController(IOptions <WebSettings> webSettings, IValidateCode validateCode, HttpContextExtension httpExtension, ICMSAdminBO cmsAdminBO, ICMSAdminCookie cmsAdminCookie) : base(webSettings, validateCode, httpExtension, cmsAdminBO, cmsAdminCookie) { }