创建项目 net5就自带上了swaggerUI,见红色 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDo…
介绍 作为一个开发人员,你知道如何分析自己开发的Api性能么? 在Visual Studio和Azure中, 我们可以使用Application Insight来监控项目.除此之外我们还可以使用一个免费工具Stackify Prefix,它允许追踪所有的Http请求, 这里有一篇博客讲解了如何使用Stackify Prefix(Scalable and Performant ASP.NET Core Web APIs: Profiling and Monitoring). 本文我将引入另外一个工…
参考地址,官网:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.2&tabs=visual-studio 与https://www.jianshu.com/p/349e130e40d5 当一个WebApi完成之后,书写API文档是一件非常头疼的事,因为不仅要写得清楚,能让调用接口的人看懂,又是非常耗时耗力的一件事.在之前的一篇随笔中(…
Autofac前面写了那么多篇, 其实就是为了今天这一篇, Autofac在MVC和WebApi中的应用. 一.目录结构 先看一下我的目录结构吧, 搭了个非常简单的架构, IOC(web), IBLL, BLL, IDAL, DAL, Helper public interface ITestBll { void Say(List<string> msg); } 我里面都是为了实现Say方法的. public class TestBll : ITestBll { public void Say…
在MVC的WebApi中默认是没有开启Session会话支持的.需要在Global中重写Init方法来指定会话需要支持的类型 public override void Init() { PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest; base.Init(); } void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { H…
WebApi 身份验证方式 asp.net WebApi 中有三种身份验证方式 个人用户账户.用户可以在网站注册,也可以使用 google, facebook 等外部服务登录. 工作和学校账户.使用活动目录,Office 365等方式进行身份验证. Windows 身份验证.在局域网中使用. 个人用户账户方式下又又两种登录方式: 本地登录.用户在网站注册,网站保存用户的登录名和密码散列值.登录时,用户提供登录名和密码,网站使用 asp.net identity 系统进行身份验证. 社交登录.使用…
demo地址:demo-swagger-springboot springboot中swaggerUI的使用 1.pom文件中添加swagger依赖 2.从github项目中下载swaggerUI 然后把dist目录下的所有文件复制到springboot项目的webapp下面,修改index.html中的: url = "http://petstore.swagger.io/v2/swagger.json";为---------> url="http://localho…
相比json来说,好处是速度更快,带宽占用更小.其效果大致等于json+Gzip. 在webapi中使用protobuf的方法为: 引用nuget包 Install-Package protobuf-net 为DTO添加注解  [ProtoContract] public class Product { [ProtoMember()] public int Id { get; set; } [ProtoMember()] public string Name { get; set; } [Pro…
扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat) 一.背景 大家在使用WebApi时,会用到DateTime为参数,类似于这样: //url: xxx/2016-09-08 [HttpGet("{date:datetime}")] public string Get(DateTime date) { return date.ToString("yyyyMMdd"); } 但是":d…
一.Forms认证 1.在webapi项目中启用Forms认证 Why:为什么要在WebAPI中使用Forms认证?因为其它项目使用的是Forms认证. What:什么是Forms认证?它在WebAPI中就是一个MessageHandle,具体请查找关键字“ASP.NET Forms” How:如何启动Forms认证? 最简单的是通过配置启动Forms认证: <system.web> <authentication mode="Forms"> <forms…