301RedirectsFromOldSite

Exception in template (Designs\BocaBearings\Paragraph\301RedirectsFromOldSite.cshtml): System.ArgumentException: Redirect URI cannot contain newline characters.
   at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
   at CompiledRazorTemplates.Dynamic.acccadfba.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.Output()
@{ //get querystring value from the input string originalUrl = System.Web.HttpContext.Current.Request["OriginalUrl"] ?? ""; string newUrl = ""; //remove trailing slash if there is one if (originalUrl.Length > 1 && originalUrl.Substring(originalUrl.Length - 1) == "/") { originalUrl = originalUrl.Substring(0, originalUrl.Length - 1); } //remove beginning slash if there is one if (originalUrl.Length > 1 && originalUrl.Substring(0, 1) == "/") { originalUrl = originalUrl.Substring(1); } //add some basic sql injection prevention originalUrl = originalUrl.Replace("'", "").Replace(";", "").Replace("--", ""); var sqlResults = Dynamicweb.Database.CreateDataReader( String.Format("SELECT TOP 1 * FROM _301Mappings WHERE QueryURL = '{0}' OR FriendlyURL = '{0}'", originalUrl) ); while (sqlResults.Read()) { //there should only be 1 result (max) but if there are more use any of them newUrl = sqlResults["NewURL"].ToString(); } //Parse for possible variable {ProductPage} newUrl = newUrl.Replace("{ProductPage}", "/Default.aspx?ID=" + Pageview.Area.Item["ProductDetail"].ToString()); if (String.IsNullOrEmpty(newUrl)) { newUrl = "/"; } <div>Original: @originalUrl<br /> New: @newUrl</div><br /> <div>@Pageview.Area.Item["ProductDetail"]</div> System.Web.HttpContext.Current.Response.Redirect(newUrl); }