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?
IWebHostEnvironment is included in the Microsoft. AspNetCore. Hosting package, you simply need to add it as a reference to your project by right clicking on your project file and selecting 'Manage Nuget Packages' then searching for Microsoft. AspNetCore.
For registering the interface and classes, you need to go in the Program class (As Startup class is no more with . NET 6) and use these methods i.e "AddScoped" || "AddTransient" || "AddSingleton" as it defines the lifetime of the services. STEP 5 - Go to Program class and register it.
IApplicationBuilder An object that provides the mechanisms to configure an application's request pipeline.
As an alternative to using the static CreateDefaultBuilder method, creating a host from WebHostBuilder is a supported approach with ASP.NET Core 2. x. When setting up a host, Configure and ConfigureServices methods can be provided. If a Startup class is specified, it must define a Configure method.
Add dependency:
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />
Then in source code add:
using Microsoft.AspNetCore.Http;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With