The URLRewrite middleware in .NET Core can rely on Config dependency injection/scoped service by registering it as a scoped service in the Startup.cs file.
First, a new class that implements the IUrlRewriter interface needs to be created. This class will contain the logic for the URL rewriting.
Next, the class needs to be registered in the ConfigureServices method in the Startup.cs file as a scoped service using the AddScoped extension method.
public void ConfigureServices(IServiceCollection services) { // Register the UrlRewriter as a scoped service services.AddScoped<IUrlRewriter, UrlRewriter>(); }
Once registered, the middleware can then be added to the pipeline in the Configure method, and it will have access to the Config dependency injection/scoped service.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // Add the UrlRewrite middleware to the pipeline app.UseMiddleware<UrlRewriteMiddleware>(); }
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-15 13:04:56 +0000
Seen: 10 times
Last updated: May 15 '23
What is the process for setting up a windows disk in .Net Core?
What's the process of configuring SpaProxyServerUrl in .net core 6 according to the environment?
Is it possible to globally install System.Data.OleDb?
What is the method to discover and terminate a process in .net?
Does Asp .Net Core Identity log out automatically after a certain period of time?
Why isn't the user interface updating when adding a custom object with data binding in .NET MAUI?
How can an application communicate with a service in the C# .NET Framework?
How can I send messages to multiple phone numbers using Twilio SMS and .net?
What is the process for working with dynamics 365 using .net 6/7?