webapi

WebRTC stuck in connecting state when ice servers are included (remote candidates causing issues even over LAN)

旧巷老猫 提交于 2020-07-10 03:13:00
问题 The bounty expires in 7 days . Answers to this question are eligible for a +50 reputation bounty. David Callanan wants to draw more attention to this question. I was temporarily creating an RTCPeerConnection without any iceServers while attempting to solve a previous issue. let peer = new RTCPeerConnection(); This has been working perfectly on my local network. However device that's not on the same network (for example, a mobile on 4G) would not connect. I remembered that I had to add back

Configure Swagger Authentication with Firebase (google) in .Net core

久未见 提交于 2020-06-08 15:12:05
问题 Integrating swagger and firebase is really hard because google token request and response is not standard. so I used password flow and add a middleware in .net core 3.1 Web API to authenticate swagger 5.x I hope it helps. The first step is configuring your API to use Firebase for token validation. so we need to add this code to the startup. services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme =

Validate Identity Server token in NodeJS API

人走茶凉 提交于 2020-06-01 06:03:12
问题 I have a token that it has been issued by Identity Server (IDP) and then have a NodeJS application and I want to validate that token in NodeJS API? I'm trying to use jose (based on this) but I did not know how to use it. Is it possible to do it? NOTE: In my ASP NET CORE API , here that is as a client I have to only add the following command in startup class to validate my API ? services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)

How to unit test a Web API controller using XUnit

六月ゝ 毕业季﹏ 提交于 2020-05-30 07:44:26
问题 I am trying to unit test a method within my controller in my Web API using XUnit. The role of the method is to get a single title, by ISBN, from the database. The issue I came across during unit testing is that I am unsure how to insert the dummy data that I must perform the test on, as well as how the Assert function works. TitleController.cs [ApiController] [Route("titlecontroller")] public class TitleController : Controller { private IGtlTitleRepository _gtlTitleRepository; public

.Net Core技术研究-WebApi迁移ASP.NET Core2.0

老子叫甜甜 提交于 2020-04-05 15:06:11
随着ASP.NET Core 2.0发布之后,原先运行在Windows IIS中的ASP.NET WebApi站点,就可以跨平台运行在Linux中。我们有必要先说一下ASP.NET Core。 ASP.NET Core 是新一代的 ASP.NET,第一次出现时的代号为 ASP.NET vNext,后来命名为ASP.NET 5,随着它的完善与成熟,最终命名为 ASP.NET Core,这表明它已不是 ASP.NET 的升级,而是一个重新设计的Web开发框架。而它一个非常重要的变化就是它不再依赖于IIS,而是一个独立的自寄宿的控制台应用程序,这也是它可以跨平台的根本。 两个关键词: IIS解耦和独立自寄宿的控制台应用程序。 我们对比一下ASP.NET和ASP.NET Core。ASP.NET 是强依赖于Windows IIS的,因为System.Web 中有很多方法都是直接调用的 IIS相关的 API,同时它还是驻留在IIS进程中的。然而 ASP.NET Core 运行时则是一个完全独立的控制台应用程序,它有自己的 Kestrel Server,可以直接对外部提供服务。不过当前已有的 Kestrel Server 的功能相对比较简单,所以我们还是需要一个反向代理服务器将 Kestrel 服务器保护起来。因此,部署在Linux环境下,可以考虑Nginx+Kestrel Server的组合

WebAPI从Server端push消息到Client

Deadly 提交于 2020-04-04 17:54:17
WebAPI从Server端push消息到Client 写本篇的起因,是重构一个现有的WinForms程序,将Server端的部分逻辑从raw socket通讯的方式,改为调用WebAPI。重构则是因为原先代码有严重的性能问题,而组里并没有能够写好socket通讯的同学。 WebAPI的编写相对就简单多了,但原先从Server端push消息到Client的功能就需要找到替代的解决方案。所以有了本篇对于SignalR的介绍。 “ASP.NET Core SignalR 是一个开源代码库,它简化了向应用添加实时 Web 功能的过程。 实时 Web 功能使服务器端代码能够即时将内容推送到客户端。”看不懂不能怪我,MSDN上的原话。简单可以理解为SignalR是一个基于WebSocket的库,能够帮助我们避免直接使用socket,而写出一些性能夸张的代码…… SignalR的基本push流程是这样的,首先Server端有一个Hub类,Hub类中会定义一个方法,该方法会在某个时机被触发,而在该方法内部,会有一个Clients.All.SendAsync之类的操作。然后通过该SendAsync方法,来将消息内容传递给事先定义好的Client端的方法。 public class TestCaseHub : Hub { public async Task SayHello() { await

.net core webapi Controller中处理http请求和响应

时光怂恿深爱的人放手 提交于 2020-03-23 18:18:01
在实际工作中,企业框架往往对Http请求和响应的body制定了一定的规范,这样每次编写Controller中Action方法时,有以下两个问题要解决: 都要解析请求报文以获取有用的参数 在返回时,根据规范去包装响应内容 为了减少工作量,我们可以编写一段通用的代码,在请求的时候对请求body进行解析,在响应的时候对body进行包装。 我这里采用的方式是在自己写Controller类上加一个自定义的特性[HttpMessageAttribute],这个特性继承自[ActionFilterAttribute],[ActionFilterAttribute]特性有以下几个常用的虚方法: #region 程序集 Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 #endregion //在Action执行之后调用 public virtual void OnActionExecuted(ActionExecutedContext context) { } //在Action执行之前调用 public virtual void OnActionExecuting(ActionExecutingContext context) { } /

.net webapi 接收保存图片到服务器,并居中剪裁压缩图片

戏子无情 提交于 2020-03-18 10:00:08
每天解决一些c#小问题,在写微信小程序,或者一些手机软件接口,我们经常要用到上传图片到服务器,或者使用图床去保存我们的图片。 这次就简单明了的来梳理一下如何实现图片的接受和对接受到的图片进行一些处理。 一、实现图片的接收 1.首先要明确现在大部分前端的传输图片的统一规范都是通过 POST请求+form表单 提交文件的形式 话不多说上代码,这里是上传一张图片的示例,我用的是时间戳命名 [HttpPost,Route("UpLoadImageFiles")] public string UpLoadImageFiles(string suffix)//suffix是后缀的意思,可以自己判断,也可以前端传输 { var files = HttpContext.Current.Request.Files;//首先先确定请求里夹带的文件数量 if (files.AllKeys.Any())//如果存在文件 { using (HttpClient client = new HttpClient()) { HttpContextBase HttpContext = (HttpContextBase)Request.Properties["MS_HttpContext"]; var text = HttpContext.Request.Files[0].InputStream;//获取到文件流

WebApi 自宿主

纵然是瞬间 提交于 2020-03-17 15:00:39
WebApi和WCF一样可以自宿主,即可以不用搭载在网站上。 1.引入必须的dll 2.开启监听 var config = new HttpSelfHostConfiguration("http://localhost:3333"); config.Routes.MapHttpRoute("default", "api/{controller}/{id}", new { id = RouteParameter.Optional }); var server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); 来源: https://www.cnblogs.com/fat-girl/p/12510141.html

ASP.NET WebAPI框架解析第二篇(HttpModule的创建和使用)

无人久伴 提交于 2020-03-15 17:19:37
我们先看一下执行流程图 图中画红圈的部分便是HttpModule,在说创建HttpModule之前,先说一下HttpApplication对象,HttpApplication对象由Asp.net框架创建,每个请求对应一个HttpApplcation实例对象,Asp.Net框架内部维护了一个HttpApplication对象池,可以复用该对象,以便节省服务器资源。HttpApplication对象内部有许多事件,其中的一些事件如下: BeginRequest Asp.net处理的第一个事件,表示处理的开始 AuthenticateRequest 验证请求,一般用来取得请求用户的信息 PostResolveRequestCache 已经完成缓存的获取操作 …… EndRequest 本次请求处理完成 其中 PostResolveRequestCache 这个事件就被路由模块监听了。我们看看一个标准HttpModule模块的接口定义是怎么样的。 public interface IHttpModule { void Init(HttpApplication context); void Dispose(); } 注意到 Init(HttpApplication context) 这个方法,每注册一个HttpModule模块,Asp.Net框架内部通过反射获取对应的程序集