Question 'HttpResponse' does not contain a definition for 'WriteAsync'?

Joined
Aug 14, 2021
Messages
11
Programming Experience
Beginner
Hello,I have 3 errors that are popping and I have no understanding why they appeared,since the other file that I open from the courses works perfectly. These code is from the startup.cs file. Any help would be just amazing to receive since I just started and I already have simple problems.
C#:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication1
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see [URL='https://aka.ms/aspnetcore-hsts']Enforce HTTPS in ASP.NET Core[/URL].
                app.UseHsts();
            }

            //1
            app.Use(async (context, next) => {


                if (context.Request.Method == HttpMethods.Get
                    && context.Request.Query["iscertified"] == "true")
                {
                    await context.Response.WriteAsync("Message from Custon Middleware \n");
                }
                await next();
            });




            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
                             {
                                 endpoints.MapGet("/", async context =>
                                                  {
                                                      await context.Response.WriteAsync("Hellow World");
                                                  });


                                 endpoints.MapControllerRoute(
                                     name: "default",
                                     pattern: "{controller=Home}/{action=Index}/{id?}");
                             });
        }
    }
}
 

Attachments

  • Screenshot 2021-09-10 200121.png
    Screenshot 2021-09-10 200121.png
    35.5 KB · Views: 3
  • Screenshot 2021-09-10 200208.png
    Screenshot 2021-09-10 200208.png
    217.7 KB · Views: 3
Last edited by a moderator:

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,209
Location
Norway
Programming Experience
10+
Top Bottom