What is the difference between Run() and Use() methods in IApplicationBuilder?
  • Use() method: Used to create a simple middleware which can be "chained" to other functions over the pipeline. Takes two arguments: RequestDelegate and HttpContext. It is chained by calling the next() method on the RequestDelegate.
  • Run() method: "short-circuit" the request pipeline for a given condition. Takes a single argument of HttpContext and can be used to write on the Response.
app.Use(async (context, next) =>
    // Do something here
    // Call the next middleware
    await next.Invoke();

app.Run(async context =>
      // short-circuit the request 
      // write a response back
      await context.Response.WriteAsync("Hello from Run");

ASP.NET Core •  Added 3 months ago

How can you use .NET framework class libraries in a .NET Core application?

* Class libraries which are built against .NET framework can be referenced and used inside a .NET Core application starting from .NET Core 2.x by mean ...

What is the difference between a Middleware and a HttpModule?

* A HttpModule is core to the ASP.NET MVC framework, while a Middleware is native to the ASP.NET Core * Both Middleware and HttpModule are pieces of ...

What is the difference between Response.Redirect() and Server.Transfer() ?

* Response.Redirect() redirects browser to another page, history is updated, trip back to client where browser loads the new page. * Server.Transfer( ...

How do you handle errors Globally in ASP.NET Core?

We can make use of the built-in UseExceptionHandler() middleware for catching Global Errors in ASP.NET Core. ``` app.UseExceptionHandler(err => ...

How do you design a strongly-typed class for a configuration?

To create a strongly-typed class for binding to a configuration section: * The property names and their types match the key names and their value t ...

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept