我有以下用于执行重定向的正则表达式
string requestedPath = HttpUtility.UrlDecode(this.StripLanguage(currentContext.InputUrl.AbsolutePath));
string requestedPathAndQuery = HttpUtility.UrlDecode(currentContext.InputUrl.PathAndQuery);
string requestedRawUrl = HttpUtility.UrlDecode(currentContext.InputUrl.PathAndQuery);
string requestedUrl =
HttpUtility.UrlDecode(
string.Concat(
currentContext.InputUrl.Scheme,
"://",
currentContext.InputUrl.Host,
requestedRawUrl));
string requestedRawUrlDomainAppended = HttpUtility.UrlDecode(currentContext.InputUrl.AbsoluteUri);
string requestedPathWithCulture = HttpUtility.UrlDecode(currentContext.InputUrl.AbsolutePath);
var finalRequestedURL = string.Empty;
finalRequestedURL = Regex.IsMatch(requestedPathAndQuery,matchPattern.Trim(),RegexOptions.IgnoreCase)
? requestedPathAndQuery
: Regex.IsMatch(requestedPath,matchPattern.Trim(),RegexOptions.IgnoreCase)
? requestedPath
: Regex.IsMatch(requestedPathWithCulture,matchPattern.Trim(),RegexOptions.IgnoreCase)
? requestedPathWithCulture
: Regex.IsMatch(requestedRawUrl,matchPattern.Trim(),RegexOptions.IgnoreCase)
? requestedRawUrl
: Regex.IsMatch(requestedUrl,matchPattern.Trim(),RegexOptions.IgnoreCase)
? requestedRawUrlDomainAppended
: string.Empty;
matchPattern变量是 URL 。示例:(.*)/articles/my-article(.*)应重定向到http://www.google.com
正则表达式工作正常,但是当涉及到大量请求时,我们的 CPU 会达到 100%。
有什么解决方案可以优化上述内容吗?
梵蒂冈之花
森林海
相关分类