Edi Wang

.NET and Azure Developer

Web API

Call API with Windows Authentication from Blazor Web Assembly

I was rewriting an old Angular application to Blazor Web Assembly a couple of days ago. The App is an internal tool, which uses a backend API that has Windows Authentication. However, when calling API from HttpClient that UseDefaultCredentials, Blazor will throw PlatformNotSupportedException. The majority of internet search so far tell you it's not possible. Really? Let's see how to make it work! …
.NET Web API Blazor

Migrating an ASP.NET Core Web API Project to Azure Function

Some time ago, I successfully migrated an ASP.NET Core Web API project to the latest Azure Function V3, thereby taking advantage of the serverless features of the Azure platform to reduce operation and maintenance costs by 10 times. This article will introduce the key steps and practices in the migration process to help you migrate similar Web API projects. Project background This Web API …
.NET Web API Azure Azure Function

ASP.NET Web API 跨域访问(CORS)要注意的地方

前几天我在帮队友撸一个WebAPI的跨域访问问题,被爆出了翔,今天正好有时间总结一下经验。 首先一个最坑之坑,也是ASP.NET官网上都没有提到的坑,是Web.config里的配置。大家看这个建立WebAPI项目之后,默认的Web.config: 它居然把OPTIONS类型的请求给撸掉了!然而,在jQuery等框架里发起CORS请求的时候,虽然你写的可能是“GET”,但是现在的浏览器是会自动把这个GET先撸成OPTIONS去访问服务的,这也叫“preflight”请求。如果你的服务拒绝OPTIONS这个verb,你会得到一个405的结果(用fiddler就可以看到)。 所以,要让WebAPI支持CORS,第一步就是在web.config里把“”删掉。 接下来,要实现CORS,有两种办法。一是在客户端完成(要求对WebAPI做少量拓展),二是在服务端(WebAPI)本身做支持。 一、客户端 …
ASP.NET Web API CORS

ASP.NET WebAPI 自动生成帮助文档

目前在做的项目里要用到RESTful Service,一开始是用WCF WebHttpBinding撸的,但我知道WebAPI才是最适合的,正好现在VS2013 RTM了,Web API 2也跟着ASP.NET MVC5一起发布了,于是今天就把Service用Web API 2重写了一下。 我选择Web API的一个重要原因就是因为可以自动生成文档,省去了开发人猿不少宝贵的时间。以前在用Web API第一代的时候,自动生成帮助文档的功能默认是不完整的,现在到了Web API 2,这个功能已经通过NuGet包的形式很好的整合到了一起。我们来看一下吧! 首先,用VS2013创建的Web API 2项目会默认带有Microsoft ASP.NET Web API Help Page的包。如果没有,就需要手动去NuGet上安装。 在安装了这个包以后,你的Web API项目目录里会多一个 …
ASP.NET Web API