private void CreateRegEx() { var urlHelper = new UrlHelper(); if (IgnoreCase) _regex = new Regex(urlHelper.HandleRootOperator(_virtualUrl), RegexOptions.IgnoreCase | RegexOptions.Compiled | _regexOptions); else _regex = new Regex(urlHelper.HandleRootOperator(_virtualUrl), RegexOptions.Compiled | _regexOptions); }
private void CreateRegEx() { UrlHelper urlHelper = new UrlHelper(); if (IgnoreCase) { this.regex = new Regex(urlHelper.HandleRootOperator(virtualUrl), RegexOptions.IgnoreCase | RegexOptions.Compiled | regexOptions); } else { this.regex = new Regex(urlHelper.HandleRootOperator(virtualUrl), RegexOptions.Compiled | regexOptions); } }
private void CreateRegEx() { var urlHelper = new UrlHelper(); if (IgnoreCase) { _regex = new Regex(urlHelper.HandleRootOperator(_virtualUrl), RegexOptions.IgnoreCase | RegexOptions.Compiled | _regexOptions); } else { _regex = new Regex(urlHelper.HandleRootOperator(_virtualUrl), RegexOptions.Compiled | _regexOptions); } }
/// <summary> /// Redirects the URL. /// </summary> /// <param name="app">The app.</param> /// <returns>true if redirected, false if not</returns> private bool RedirectUrl(HttpApplication app) { string requestUrl; bool redirected = false; // First, checking for Redirects lockRedirects.AcquireReaderLock(0); foreach (RewriteRule rewrite in Redirects) { if (rewrite.Redirect == RedirectOption.Domain) { requestUrl = app.Request.Url.AbsoluteUri; } else { requestUrl = app.Request.RawUrl; } if (rewrite.IsRewrite(requestUrl)) { bool includeQueryStringForRewrite = (rewrite.RewriteUrlParameter & RewriteUrlParameterOption.IncludeQueryStringForRewrite) != 0; string urlForRewrite = requestUrl; string requestQuerystring = string.Empty; int pos = requestUrl.IndexOf('?'); if (!includeQueryStringForRewrite && pos >= 0) { requestQuerystring = requestUrl.Substring(pos + 1); urlForRewrite = requestUrl.Substring(0, pos); } string destinationUrl = rewrite.RewriteUrl(urlForRewrite); if (includeQueryStringForRewrite) { destinationUrl = urlHelper.HandleRootOperator(destinationUrl); } else { destinationUrl = JoinUrlParameter(urlHelper.HandleRootOperator(destinationUrl), requestQuerystring); } StringBuilder sb = new StringBuilder(); if (rewrite.Redirect == RedirectOption.Domain) { sb.Append(destinationUrl); } else { sb.Append(app.Request.Url.Scheme); sb.Append("://"); sb.Append(app.Request.Url.Authority); sb.Append(destinationUrl); } // Nur für den Fall, dass die Weiterleitung explizit auf permanent // gestellt ist, 301 festlegen - sonst kann das Konsequenzen haben if (rewrite.RedirectMode == RedirectModeOption.Permanent) { app.Response.StatusCode = 301; } else { app.Response.StatusCode = 302; } // Location MUST be absolut. app.Response.AddHeader("Location", sb.ToString()); app.Response.End(); redirected = true; break; } } lockRedirects.ReleaseReaderLock(); return(redirected); }