ASP.NET Core url rewrite only domain

后端 未结 1 590
天涯浪人
天涯浪人 2021-01-15 10:41

I am trying to change my old domain to new one and I have huge data on my website. I need to change only my domain by url rewriting.

When I request:



        
1条回答
  •  情歌与酒
    2021-01-15 10:52

    Have you considered URL Rewriting Middleware?

    It's pretty simple.

    1. Drop a IISUrlRewrite.xml file in the root of your application folder. Mark it as "Content" and "Copy to output directory" set to true, looks like this in your csproj
      
        
          Always
        
      
    
    1. Add following content in the file
    
          
        
          
          
            
          
          
        
       
    
    
    1. Register the URL rewrite module in the Configure method of your Startup.cs file
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {   
        // Irrelevant code omitted
    
        using (var iisUrlRewriteStreamReader = File.OpenText(Path.Combine(env.ContentRootPath, "IISUrlRewrite.xml")))
        {
            var options = new RewriteOptions().AddIISUrlRewrite(iisUrlRewriteStreamReader);
            app.UseRewriter(options);
        }
    
        // Irrelevant code omitted
    }
    

    0 讨论(0)
提交回复
热议问题