Reputation: 153
I am following examples for creating middleware in Mvc6 and all of the examples use the WriteAsync function. Something like this:
if (HttpContext.Request.Path.Value == "/MyHttpHandler")
{
HttpContext.Response.WriteAsync("This is my HttpHandler ...");
}
The error I get is: HttpResponse
does not contain a definition for WriteAsync
and no extension method 'WriteAsync' accepting a first argument of type HttpResponse
could be found.
The project was creating in VS2017
, Asp.Net 5 Template Web Application.
Project dependency:
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
Where is the WriteAsync function?
Upvotes: 12
Views: 8239
Reputation: 334
use NuGet package manager command line and run this command
Install-Package Microsoft.AspNetCore.Http.Abstractions -Version 2.2.0
and import this namespace
using Microsoft.AspNetCore.Http;
Upvotes: 1
Reputation: 741
Add dependency:
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />
Then in source code add:
using Microsoft.AspNetCore.Http;
Upvotes: 28
Reputation: 68800
Consider writing a simple Middleware. There you can access and edit the Response as well.
Upvotes: 1
Reputation: 687
one package is missing. please add this package "Microsoft.AspNetCore.Http.Abstractions
" and use the namespace "using Microsoft.AspNet.Http;
" to get the intellisense in your code.
Upvotes: 2