用于记录在项目中使用到的方法、属性、操作,持续更新中

.net core 开源地址

图片上传:

public async Task<IActionResult> Upload([FromServices]IHostingEnvironment environment)
{
var result = new BaseResult();
string path = string.Empty;
var files = Request.Form.Files;
if (files == null || files.Count() <= ) {
result.Msg = "请选择上传的文件。";
return Json(result);
}
//格式限制
var allowType = new string[] { "image/jpg", "image/png" , "image/jpeg" };
if (files.Any(c => allowType.Contains(c.ContentType)))
{
string strpath = Path.Combine("images", DateTime.Now.ToString("MMddHHmmss"));
path = Path.Combine(environment.WebRootPath, strpath);
using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
await files[].CopyToAsync(stream);
}
result.Data = strpath;
}
else
{
result.Msg = "图片格式错误";
}
return Json(result);
}

ps:获取上传文件信息 可使用  IFormFileCollection 或者 Request.Form.Files来获取。

.net core 2.0发布后,不把 view 文件编译打包,修改 csproj文件中 PropertyGroup 节点,配置节MvcRazorCompileOnPublish设为false就行

 <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>

发布如图所示

Drawing绘制图片,官方包:

System.Drawing.Common

静态文件的使用

在项目中静态文件的使用需要在Startup中的Configure方法中增加:

//使用静态文件
app.UseStaticFiles();

这样就可以访问所有wwwroot目录下的静态文件,但是若想访问Views/Menu/Index.js文件,还需要在Configure方法中增加:

app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory())
});
//在页面的引用方式
@section scripts{
<script src="~/Views/Department/Index.js"></script>
}

在mvc中加载其他页面到当前页面:

@Html.Partial("_Edit")

@RenderSection 详解:http://www.cnblogs.com/Joetao/articles/4191682.html

session过期验证:

 /// <summary>
/// 拦截控制器
/// </summary>
public class InterceptController : Controller
{
public override void OnActionExecuted(ActionExecutedContext context)
{
byte[] result;
//获取session的值
context.HttpContext.Session.TryGetValue("UserInfo", out result);
if (result==null)
{
//重定向到登录页面
context.Result = new RedirectResult("/Login");
}
base.OnActionExecuted(context);
}
}

最新文章

  1. 设计模式之迪米特原则(LOD)(最少知识原则)
  2. 使用WebRTC搭建前端视频聊天室——点对点通信篇
  3. [知识整理]Java集合
  4. java 中遍历hashmap 和hashset 的方法
  5. python tornado框架使用
  6. IIS开启伪静态后html静态页面无法访问的解决方法
  7. 移动端 iphone touchmove滑到边界(浏览器地址拦及以上) touchend失效解决办法
  8. 如何使用kali的Searchsploit查找软件漏洞
  9. 车牌识别OCR—易泊时代智慧城市解决方案模块
  10. 进击Node.js基础(一)
  11. 【Canal源码分析】parser工作过程
  12. Mysql 上亿级数据导入Hive思路分享
  13. tp5 删除服务器文件
  14. SQL Server 2012-2016-2017 简体中文版下载和序列号
  15. socket编程及API简介
  16. inline详解
  17. Criteria查询
  18. 图文例解C++类的多重继承与虚拟继承
  19. P4 PI库安装
  20. Totem协议(SRP/RRP)讲解

热门文章

  1. javascript修改div大小遮挡页面渲染问题
  2. 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (六) 树莓派查询子节点温湿度数据
  3. 最新版ABP 动态WebAPI 日期转json带T的解决方案| ABP DateTIme Json format
  4. vue开发完成后打包后图片路径不对
  5. SQL DATACOMPARE 实现两个数据库的同步处理.
  6. [转帖]Cookies和Session的区别和理解
  7. centos 升级内核(编译安装)
  8. elasticsearch6 学习之安装
  9. Embarcadero Delphi 7 Enterprise 7.0.4.453 中文版
  10. java使用Cookie判断用户登录情况