当前位置:网站首页>WebApi记录
WebApi记录
2022-08-07 03:16:00 【故里2130】
目录
1.加上Name,就是一个参数
[HttpGet(Name ="GG{id}")]
结果是

不加Name,就是一个路径
[HttpGet("GG{id}")]
结果是

带斜杠,[HttpGet("GG/{id}")] ,就是一个子集的路径了

2.带参数
[HttpGet("GG/{id}")]
public String Get(string id,string a)
{
return id;
}效果

3.返回数据的时间格式化
nuget安装 Microsoft.AspNetCore.Mvc.NewtonsoftJson
只需要在Program.cs 文件下添加几行代码
找到builder.Services.AddControllers()
builder.Services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});4.Startup.cs文件介绍
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
//初始化,依赖注入IOC
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//运行的时候调用
services.AddControllers();
//注册Swagger服务
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication11", Version = "v1", Description="23335" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//.net core中内置kestrel主机,管道模式,中间件,
//这里随意配置中间件,拓展性非常大
if (env.IsDevelopment())
{
//开发者模式的话,启动异常
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication2 v1"));
app.Use(async (context, next) =>
{
//logger.LogInformation("M1request"); //使用中间件
await next(); //执行下一个中间件,
//logger.LogInformation("M1response"); //先执行一个,结束后返回到这个,再执行这个使用中间件
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();//结束
});
}
}
}
5.AOP,面向切面
.net。先走构造,再走filter
.net core。先走filter,再走构造,再走filter
例如:onResourceExecuted() 做缓存资源,如果缓存里面有值,下次就不会执行了
Actionfilter,做日志,数据验证,性能监控,数据压缩
例如:onActionExecuing() 先执行。 onActionExecuted() 后执行
获取方法名字:context.RouteData.Values["action"] 参数:context.ActionArguments
全局->控制器->方法
core套娃:中间件,action
6.launchSettings中,设置,直接访问
"launchUrl": "swagger/index.html"
7.鉴权授权,token
传统:session/cookies
1.鉴权中心授权
2.请求api+token,非对称可逆加密
8.缓存,性能优化
二八原则,20%是增删改,80%是查询
AOP,面向切面编程:
在执行某一个方法之前,做事情,再执行之后,再做事情。
5大filter,继承Attribute、IResourceFilter,实现接口,做缓存
先走onResourceExecuing() ,再走方法,最后走onResourceExecuted()

如果Nginx加了代理,代码又写了缓存,会产生问题。
网址第一次点击不变,代码产生缓存,第二次点击,网页变化了。
解决办法,内存缓存,使用Redis缓存。
依赖注入,IRedisStringService
边栏推荐
- pytorch: dataloader custom data set production
- 服务器正文23:定时器设计与实现(8/7)
- 【LeetCode每日一题】——69.x的平方根
- KingbaseESV8R3对于order by null列的处理
- Dangerous, please replace BeanUtils in the code immediately
- MySQL中自带的表
- scala object class基础语法讲解
- Wechat applet's homestay room reservation uniapp applet
- BI技巧丨筛选重置
- STM32 - RTC real-time clock principle + BKP register principle
猜你喜欢

跨行求职数分的面试经验 + 未来职业规划

损失函数_相似度计算_距离计算

云虚拟机top命令的%st解读

BI skills丨Filter reset

【FLink】Assigned key must not be null

STM32 - RTC real-time clock principle + BKP register principle

How to smoothly render tens of millions of 2D objects with WebGPU: based on the ray tracing line

Implement caching mechanism using soft references

TensorFlow学习记录(五):卷积神经网络

Dangerous, please replace BeanUtils in the code immediately
随机推荐
Loss function_similarity calculation_distance calculation
分享一些 VsCode 各场景相关的高级调试与使用技巧
STM32 - RTC real-time clock principle + BKP register principle
什么是传输网、核心网、承载网、接入网?
The process of kafka-flink-mysql
2022.8.6-----leetcode.1408
力扣(LeetCode)218. 天际线问题(2022.08.06)
聊聊字典那些事
基于FPGA的fir滤波器设计verilog实现
微信小程序获取页面自定义属性值
laravel 事件监听
如何用WebGPU流畅渲染千万级2D物体:基于光追管线
权重的初始化总结
2022年NeurIPS智能驾驶大赛
广告电商系统开发功能之产品系统模块
KingbaseES V8R3集群管理和维护案例之---failover切换wal日志变化分析
activiti7入门教程
通过文件url地址获取base64;通过图片url地址获取base64;js获取文件的base64
..\USER\stm32f4xx.h(102): error: #35: #error directive: “Please select first the target STM32F4xx d
剑指 Offer II 029. 排序的循环链表-纯链表实现