asp.net web core 开发问题汇总(1)
1 ASP.NET Core 设置默认静态起始页
转载地址:ASP.NET Core 设置默认起始页(如default.html)
注:1 默认情况下ASP.NET Core应用程序时不支持静态文件的。
2 为静态文件提供存储的默认路径时wwwroot;【一定要新建wwwroot的文件夹】
2 转载自 .net core实现读取appsettings.json配置文件
3 转载自 .net core webapi 只允许POST
A 画线内容没有达到效果
通过 HttpMethodRouteConstraint 路由约束可以轻松搞定,以下是 asp.net core 3.0 的示例代码
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}",
constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("POST") }));
});B Cotroller 文件中 不实现HttpGet方法 (访问会显示404错误)4 转载[.NET] 利用 async & await 进行异步 操作5 读取post参数时,报错以下错误
Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
翻译:不允许同步操作。调用ReadAsync或将AllowSynchronousIO设置为true。
原因:.net core 默认是异步读取Stream,不允许同步。
解决:
// 适用于.net core 3.0
string s = "";
using (var buffer = new MemoryStream())
{
Request.EnableBuffering();
Request.Body.Position = ;
// Request.Body.CopyTo(buffer); 修改前
Request.Body.CopyToAsync(buffer); //修改后
byte[] b = buffer.ToArray();
s = System.Text.Encoding.UTF8.GetString(b, , b.Length);
}
6 设置appsetttings.json文件目录为网站根目录。
直接 ‘网站根路径’+appsetttings.json
提示错误 The configuration file 'appsettings.json' was not found and is not optional
.net Core 3.0 中不支持 目录+名称 的方式。
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) //添加这行
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
.Build();
Directory.GetCurrentDirectory() 当前工作的目录
7 json字符串放入key/Value列表
var postparamlist = new Dictionary<string, string>();
var jsonDocument = JsonDocument.Parse(postparamjson);
for (int i = ; i < jsonDocument.RootElement.GetArrayLength(); i++)
{
var curElement = jsonDocument.RootElement[i];
var key = curElement.GetProperty("name").ToString();
var value = curElement.GetProperty("value").ToString();
postparamlist.Add(key, value);
}
8 json文件读写
转载自https://blog.csdn.net/a15236307900/article/details/72130032
关键代码:
string all = jo.ToString();
string neame= jo["name"].ToString();
int age = int.Parse(jo["age"].ToString());
string city = jo["address"]["city"].ToString();
string baiduUrl = jo["links"][1]["url"].ToString();
所赋值可以是string,int,boolean,JTken,JObject.,JArray
创建一个空("{ }")的JObject对象,通过一定的顺序和方法,将原jo中的数据赋值到空JObject,可以实现增删排序等效果.
9 json写入 提示“”Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.“”
转载自https://blog.csdn.net/zhouyingge1104/article/details/83307637
关键点
如果是对象
//{"code":200,"检测编号":"JC1810231520411","message":"OK"
string resp =""
JObject respObj = (JObject)JsonConvert.DeserializeObject(resp);
如果是字符串
var str = "[{\"" + key + "\":\"" + value + "\"}]";
var a=JArray.Parse(str);
10 System.Text.Json 中文乱码问题
Newtonsoft.Json 一直使用的就是非严格模式咯, 而我们习惯使用的也是这种模式.
string bJsonString = System.Text.Json.JsonSerializer.Serialize(
value: jsonObject,
options: new System.Text.Json.JsonSerializerOptions
{//Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(allowedRanges: UnicodeRanges.All) 第一种
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping第二种});
asp.net web core 开发问题汇总(1)的更多相关文章
- asp.net web core 部署问题汇总
记录所有部署时遇到的问题. 微软官网部署说明 转载自:.NET Core 3.0 构建和部署(测试过可以使用) A 单文件可执行文件(文件体积较大,合并所有依赖) asp. ...
- Asp.Net Web API开发微信后台
如果说用Asp.Net开发微信后台是非主流,那么Asp.Net Web API的微信后台绝对是不走寻常路. 需要说明的是,本人认为Asp.Net Web API在开发很多不同的请求方法的Restful ...
- ASP.NET Web Froms开发模式中实现程序集的延迟加载
延迟加载是一个很大的诱惑,可以达到一些比较好的效果,比如: 1.在实体框架中,由于关联数据的数量和使用时机是不确定的,通过延迟加载,仅在使用的时候去执行关联数据的查询操作,减少无谓的数据查询操作,可以 ...
- 微软实战训练营(X)重点班第(1)课:SOA必备知识之ASP.NET Web Service开发实战
微软实战训练营 上海交大(A)实验班.(X)重点班 内部课程资料 链接:http://pan.baidu.com/s/1jGsTjq2 password:0wmf <微软实战训练营(X)重点班第 ...
- 移动平台WEB前端开发技巧汇总(转)
最近我很关注移动前端的知识,但做为一个UI设计师和web前端工作人员没有这个工作环境接触,做为门外汉,网上系统的知识也了了,一直有种雾里看花的感觉,见到本文,我自己是奉为经典.所以我分享之后又专门打笔 ...
- 水果项目第3集-asp.net web api开发入门
app后台开发,可以用asp.net webservice技术. 也有一种重量级一点的叫WCF,也可以用来做app后台开发. 现在可以用asp.net web api来开发app后台. Asp.net ...
- [目录]ASP.NET web api开发实战
第一章:Restful web service v.s. RPC style web service 第二章:ASP.NET web api v.s. WCF v.s. ASP.NET web ser ...
- asp.net web系统开发浏览器和前端工具
1. Firefox浏览器+firebug插件 下载安装Firefox浏览器后,在菜单-附加组件-扩展中,搜索firebug,下载长得像甲虫一样的安装. 在web调试中,直接点击右上角的虫子,即可调出 ...
- 移动平台WEB前端开发技巧汇总
原文 :http://uecss.com/mobile-platform-web-front-end-development-skills-summary.html 开发者们都知道在高端智能手机系统中 ...
随机推荐
- JS实现斐波那契数列的几种方法
斐波那契数列指的是这样一个数列:1.1.2.3.5.8.13.21.34.…… 前两项为1,从第三项起,每一项等于前两项的和,即F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)(n& ...
- 快速筛出topK的快速选择算法和BFPRT优化
本文始发于个人公众号:TechFlow,原创不易,求个关注 在之前Python系列当中,我们介绍了heapq这个库的用法,它可以在\(O(nlogn)\)的时间里筛选出前K大或者前K小的元素.今天我们 ...
- 修改PR Cs6,PS Cs6,AU Cs6的启动界面
转载来源:https://jingyan.baidu.com/article/09ea3ede00aeedc0aede39ca.html 百度了很多,只见PS Cs6的启动界面修改教程,PR,AU C ...
- HDU-1754 I Hate It (树状数组模板题——单点更新,区间查询最大值)
题目链接 ac代码(注意字符读入前需要注意回车的影响) #include<iostream> #include<cstdio> #include<cstring> ...
- 搜索练习题LETTERS
题目链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1212 或者http://poj.org/problem?id=1154 题目描述: 给 ...
- [CF1311C] Perform the Combo
Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...
- VMware 安装CentOS8 教程
安装一台Linux服务器 一.准备工作 1.准备一台服务器 1)下载VMware 百度下载自行安装 2.准备CentOS8 系统盘 1)CentOS8官网 https://www.centos.org ...
- Windows通过DOS命令行设置IP地址
@rem 设置固定IP地址netsh interface ip set address "本地连接" static 192.168.1.200 255.255.255.0 192. ...
- Vue中富文本编辑器(vue-quill-editor)的使用
1. 安装 npm install vue-quill-editor --save 2. 导入并挂载 import VueQuillEditor from 'vue-quill-editor' // ...
- Zjnu Stadium HDU - 3047 带权并查集板子题
#include<iostream> #include<cstring> #include<cstdio> using namespace std; +; int ...