Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mvc6, where is WriteAsync function?

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?

like image 654
Sasha Palmer Avatar asked Apr 13 '16 12:04

Sasha Palmer


People also ask

Where is IWebHostEnvironment?

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.

How do I register services in net core 6?

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.

What is IApplicationBuilder in .NET core?

IApplicationBuilder An object that provides the mechanisms to configure an application's request pipeline.

What is WebHostBuilder in asp net core?

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.


2 Answers

Add dependency:

<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />

Then in source code add:

using Microsoft.AspNetCore.Http;
like image 85
sify Avatar answered Dec 01 '22 23:12

sify


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.

like image 27
Ashish Mishra Avatar answered Dec 01 '22 23:12

Ashish Mishra