Created
June 24, 2021 23:43
-
-
Save MahdiKarimipour/7d2958da4d966fd1d22ef531d55ca739 to your computer and use it in GitHub Desktop.
Url Rewrite Custom Rule Sample
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) | |
{ | |
context.Result = RuleResult.ContinueRules; | |
return; | |
} | |
} | |
var response = context.HttpContext.Response; | |
response.StatusCode = (int)HttpStatusCode. BadRequest; | |
context.Result = RuleResult.EndResponse; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment