目录
[HttpGet(Name ="GG{id}")]
结果是

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

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

- [HttpGet("GG/{id}")]
- public String Get(string id,string a)
- {
- return id;
- }
效果

nuget安装 Microsoft.AspNetCore.Mvc.NewtonsoftJson
只需要在Program.cs 文件下添加几行代码
找到builder.Services.AddControllers()
- builder.Services.AddControllers()
- .AddNewtonsoftJson(options =>
- {
- options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
- });
- 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();//结束
- });
- }
- }
- }
.net。先走构造,再走filter
.net core。先走filter,再走构造,再走filter
例如:onResourceExecuted() 做缓存资源,如果缓存里面有值,下次就不会执行了
Actionfilter,做日志,数据验证,性能监控,数据压缩
例如:onActionExecuing() 先执行。 onActionExecuted() 后执行
获取方法名字:context.RouteData.Values["action"] 参数:context.ActionArguments
全局->控制器->方法
core套娃:中间件,action
"launchUrl": "swagger/index.html"
传统:session/cookies
1.鉴权中心授权
2.请求api+token,非对称可逆加密
二八原则,20%是增删改,80%是查询
AOP,面向切面编程:
在执行某一个方法之前,做事情,再执行之后,再做事情。
5大filter,继承Attribute、IResourceFilter,实现接口,做缓存
先走onResourceExecuing() ,再走方法,最后走onResourceExecuted()

如果Nginx加了代理,代码又写了缓存,会产生问题。
网址第一次点击不变,代码产生缓存,第二次点击,网页变化了。
解决办法,内存缓存,使用Redis缓存。
依赖注入,IRedisStringService