This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ConfigureVersioning(IServiceCollection services) | |
{ | |
services.AddControllersWithViews(o => | |
{ | |
o.UseGeneralRoutePrefix("/v{version:apiVersion}"); | |
}).AddNewtonsoftJson(options => | |
{ | |
options.SerializerSettings.MaxDepth = 1; | |
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | |
options.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.Use(async (context,next) => | |
{ | |
var url = context.Request.Path.Value; | |
if (url.Contains("/home/old-url")) { | |
context.Request.Path = "/home/new-url"; | |
} | |
await next(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app) | |
{ | |
var options = new RewriteOptions() | |
.AddRedirectToHttps(301, 5001); | |
app.UseRewriter(options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app) | |
{ | |
var options = new RewriteOptions() | |
.AddRedirectToHttpsPermanent(); | |
app.UseRewriter(options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rewrite = new RewriteOptions() | |
.AddRewrite("api/values", "api/default", true); | |
app.UseRewriter(rewrite); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rewrite = new RewriteOptions() | |
.AddRewrite(@"^Home/Resource?Id=(\d+)", "Home/$1", true); | |
app.UseRewriter(rewrite); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomRule : Microsoft.AspNetCore.Rewrite.IRule | |
{ | |
public void ApplyRule(RewriteContext context) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomRewriteRule : Microsoft.AspNetCore.Rewrite.IRule | |
{ | |
public void ApplyRule(RewriteContext context) | |
{ | |
var request = context.HttpContext.Request; | |
var host = request.Host; | |
if (host.Host.Contains("yourSampleHost", | |
StringComparison.OrdinalIgnoreCase)) | |
{ | |
if(host.Port == 8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
var options = new RewriteOptions(); | |
options.Rules.Add(new CustomRewriteRule()) | |
app.UseRewriter(options); | |
} |
OlderNewer