上传文件报413 Request Entity Too Large错误解决办法
产生这种原因是因为服务器限制了上传大小 1、nginx服务器的解决办法 修改nginx.conf的值就可以解决了 将以下代码粘贴到nginx.conf内
1 |
client_max_body_size 20M; |
可以选择在http{ }中设置:client_max_body_size 20m; 也可以选择在server{ }中设置:client_max_body_size 20m; 还可以选择在location{ }中设置:client_max_body_size 20m; 三者有区别 设置到http{}内,控制全局nginx所有请求报文大小 设置到server{}内,控制该server的所有请求报文大小 设置到location{}内,控制满足该路由规则的请求报文大小 同时记得修改php.ini内的上传限制 upload_max_filesize = 20M 注意:如果以上修改完毕后还会出现413错误的话 , 可能是域名问题 , 本人遇到过此类情况 , 记录 2、apache服务器修改 在apache环境中上传较大软件的时候,有时候会出现413错误,出现这个错误的原因,是因为apache的配置不当造成的,找到apache的配置文件目录也就是conf目录,和这个目录平行的一个目录叫conf.d打开这个conf.d,里面有一个php.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
目录内容如下: # # PHP is an HTML-embedded scripting language which attempts to make it # easy for developers to write dynamically generated webpages. # LoadModule php4_module modules/libphp4.so # # Cause the PHP interpreter handle files with a .php extension. # SetOutputFilter PHP SetInputFilter PHP LimitRequestBody 6550000 # # Add index.php to the list of files that will be served as directory # indexes. # DirectoryIndex index.php |
误就发生在这个LimitRequestBody配置上,将这个的值改大到超过你的软件大小就可以了 如果没有这个配置文件请将
1 2 3 |
SetOutputFilter PHP SetInputFilter PHP LimitRequestBody 6550000 |
写到apache的配置文件里面即可。 3、IIS服务器(Windows Server 2003系统IIS6) 先停止IIS Admin Service服务,然后 找到windows\system32\inesrv\下的metabase.xml,打开,找到ASPMaxRequestEntityAllowed 修改为需要的值,然后重启IIS Admin Service服务 1、在web服务扩展 允许active server pages和在服务器端的包含文档 2、修改各站点的属性 主目录-配置-选项-启用父路径 3、使之可以上传大文档(修改成您想要的大小就可以了,以字节为单位) c:\WINDOWS\system32\inetsrv\MetaBase.xml !企业版的windows2003在第592行 默认的预设置值 AspMaxRequestEntityAllowed="204800" 即200K 将其加两个0,即改为,现在最大就可以上传20M了。 AspMaxRequestEntityAllowed="20480000" 作者:烂孩子 链接:https://www.jianshu.com/p/3851c3d6eaf1 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
View DetailsLinq 中查询一个表中指定的字段
Linq中查询一个表中指定的几个字段: var ts = t.FindAllItems().Where(P => P.CompanyID == CurSiteUser.CompanyId).Select(s => new { BillPeriod = s.BillPeriod,FieldB=s.FieldB }).Distinct().ToList().OrderByDescending(s => s.BillPeriod).Take(24); // FindAllItems()为查询对应表的所有数据的方法; // Where 里面为查询条件 // Select 为查询的筛选条件 new{} 里面就是要查询的字段 //Distinct() 为去除重复的查询 //ToList() 为将查询转换为List<> //OrderByDescending() 表示排序字段及排序方法(倒序排列) //Take(N) 表示查询前N条数据; from:https://blog.csdn.net/linlin2294592017/article/details/27540253
View Details基于dynamic,动态给强类型Model扩展属性
直接上代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
List<TestModel> testList = new List<TestModel>(); testList.Add(new TestModel { Id = 1, Name = "A" }); testList.Add(new TestModel { Id = 2, Name = "B" }); testList.Add(new TestModel { Id = 3, Name = "C" }); List<dynamic> test = new List<dynamic>(); foreach (var item in testList) { dynamic dobj = new System.Dynamic.ExpandoObject(); var dic = (IDictionary<string, object>)dobj; var t = item.GetType(); var properties = t.GetProperties(); // 循环赋值原Model中的值 foreach (var propertyInfo in properties) { var propertyName = propertyInfo.Name; dic[propertyName] = propertyInfo.GetValue(item); } // 动态扩展属性 dic["Age"] = 3; test.Add(dic); } |
示例Model
1 2 3 4 5 |
public class TestModel { public int Id { get; set; } public string Name { get; set; } } |
js判断对象是否为空对象的几种方法
1.将json对象转化为json字符串,再判断该字符串是否为"{}" var data = {}; var b = (JSON.stringify(data) == "{}"); alert(b);//true 2.for in 循环判断 var obj = {}; var b = function() { for(var key in obj) { return false; } return true; } alert(b());//true 3.jquery的isEmptyObject方法 此方法是jquery将2方法(for in)进行封装,使用时需要依赖jquery var data = {}; var b = $.isEmptyObject(data); alert(b);//true 4.Object.getOwnPropertyNames()方法 此方法是使用Object对象的getOwnPropertyNames方法,获取到对象中的属性名,存到一个数组中,返回数组对象,我们可以通过判断数组的length来判断此对象是否为空 注意:此方法不兼容ie8,其余浏览器没有测试 var data = {}; var arr = Object.getOwnPropertyNames(data); // Object.keys(objTest).length alert(arr.length == 0);//true 5.使用ES6的Object.keys()方法 与4方法类似,是ES6的新方法, 返回值也是对象中属性名组成的数组 var data = {}; var arr = Object.keys(data); alert(arr.length == 0);//true from:https://www.cnblogs.com/jpfss/p/9105119.html
View DetailsforEach()里面使用异步函数,那如何等所有的异步函数都执行完再 进行下一步
两种方法 方法一
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
var arry = [...]; Promise.all(arry.map(function(elem){ return new Promise(function(resolve, reject){ ... resolve(result); }) })).then(function(data){ //在这就可以等所有的返回结果可以得到 }) |
方法二
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
var arry = [...]; var counter = 0; arry.forEach(function(elem){ //异步回调中 counter++; if(counter === arr.length){ //在这执行所有执行的完后的 } }) |
from:https://www.cnblogs.com/ttjm/p/13065240.html
View DetailsExtJs4发送同步请求的store
ExtJs的store默认是异步的,但有时候我们必须要发送同步请求才能满足需求,比如在多线程中,要实现同步很简单,只需继承Ext.data.proxy.Ajax,重写的同步类如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Ext.define('Ext.ux.data.proxy.Ajax', { extend: 'Ext.data.proxy.Ajax', async:true, doRequest: function(operation, callback, scope) { var writer = this.getWriter(), request = this.buildRequest(operation); if (operation.allowWrite()) { request = writer.write(request); } Ext.apply(request, { async : this.async, binary : this.binary, headers : this.headers, timeout : this.timeout, scope : this, callback : this.createRequestCallback(request, operation, callback, scope), method : this.getMethod(request), disableCaching: false }); Ext.Ajax.request(request); return request; } }); |
使用的时候,只需修改代理即可,async:false表示同步,true为异步:
1 2 3 4 5 6 7 8 |
proxy: Ext.create("Ext.ux.data.proxy.Ajax",{ async:false, url:" ", reader: { type: 'json', root: 'root' } }) |
from:https://my.oschina.net/wangdaoliang/blog/776567
View DetailsCentOS7 SpringBoot 注册服务
1.服务配置文件
1 2 |
cd /etc/systemd/system touch your_service_name.service |
1 2 3 4 5 6 |
[Unit] Description=zaomianbao [Service] ExecStart= /your_java_path/bin/java -jar /your_app_path/your_app_name.jar [Install] WantedBy=multi-user.target |
2.启动服务
1 |
systemctl start your_service_name.service |
参考: https://blog.csdn.net/weixin_37490221/article/details/80758276
View Detailslinux中启动 java -jar 后台运行程序
直接用java -jar xxx.jar,当退出或关闭shell时,程序就会停止掉。以下方法可让jar运行后一直在后台运行。 方法一 java -jar xxx.jar & 说明: 在末尾加入 & 符号 方法二 (1)执行java -jar xxx.jar后 (2)ctrl+z 退出到控制台,执行 bg (3)exit 完成以上3步,退出SHELL后,jar服务一直在后台运行。 方法三 nohup java -jar xxxx.jar & 将java -jar xxxx.jar 加入 nohup &中间,也可以实现 from:https://www.cnblogs.com/zsg88/p/9473843.html
View Detailswin10 设置系统默认编码为utf-8
win10系统支持默认编码修改.。 好处: 1.解决由utf8引起的cmd,powershell等乱码问题 2.Visual Studio 2017(其他版本没试过) 新建文件则默认为utf8 3.其他 可能的坏处: 上古版本的第三方应用软件可能会出现乱码。 由于此设置,微软官方特别说明为【beta版】(截至时间2018年10月3日),可能会引起其他未知问题,请充分考虑后再决定是否设置。 工具/原料 win10系统 方法/步骤 在小娜中搜索地区,最佳匹配中会显示【更改国家或地区】的系统设置,双击打开。 在打开的设置中点击右上角的【管理语言设置】。 然后会打开一个【区域】的窗口设置,然后点击左上角的【管理】标签。 标签切换以后,点击【更改系统区域设置】。这个需要管理员权限才能操作。 然后回打开一个【区域设置】的小窗口,有个【beta版:使用Unicode UTF-8 提供全球语言支持】的选项,打上勾,点击确定。 然后会出现一个提示【现在重新启动】的窗口,点击【现在重新启动】按钮即可。 from:https://jingyan.baidu.com/article/25648fc1471e6a9191fd002e.html
View DetailsAsp.net Core 跨域配置
一般情况WebApi都是跨域请求,没有设置跨域一般会报以下错误
1 |
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:48057' is therefore not allowed access. |
ASP.net Core 跨域有两种,全局和区域 全局跨域: 打开Startup.cs文件.在ConfigureServices方法中添加以下代码 1.配置跨域处理,允许所有来源:
1 2 3 4 5 |
//配置跨域处理,允许所有来源: services.AddCors(options => options.AddPolicy("自定义的跨域策略名称", p => p.AllowAnyOrigin()) ); |
2.允许一个或多个具体来源:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//允许一个或多个具体来源: services.AddCors(options => { // Policy 名稱 CorsPolicy 是自訂的,可以自己改 options.AddPolicy("跨域规则的名称", policy => { // 設定允許跨域的來源,有多個的話可以用 `,` 隔開 policy.WithOrigins("http://localhost:3000","http://127.0.0.1") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); |
以上两种按需求选择一种即可. Configure方法中添加以下代码
1 2 |
app.UseCors("自定义的跨域策略名称");//放到host之后【光子:20201021】 app.UseMvc(); |
局部跨域第一种用法: 1.ConfigureServices方法不变,删去Configure中的app.UseCors()方法 2.在Controller顶部或者Action方法顶部加上[EnableCors("自定义的跨域策略名称")]特性,例如
1 2 3 |
[EnableCors("自定义的跨域策略名称")] [Route("api/[controller]")] public class ContactController : Controller |
以上就可实现指定某个controller或者action跨域 禁止跨域: 禁止跨域在Controller或者Action加上[DisableCors]特性即可禁止跨域
1 2 3 4 5 6 |
[HttpGet("{id}")] [DisableCors] public string Get(int id) { return "value"; } |
参考: https://blog.johnwu.cc/article/asp-net-core-cors.html?from=singlemessage&isappinstalled=0 https://docs.microsoft.com/en-us/aspnet/core/security/cors http://www.cnblogs.com/tianma3798/p/6920704.html from:https://www.cnblogs.com/xiaoliangge/p/7650465.html
View Details