private string GetEmailBody(string templateName, RouteValueDictionary routeValues) { routeValues["controller"] = "EmailTemplates"; routeValues["action"] = templateName; var baseUri = new Uri(SystemPath.BaseUri()); var relativeUri = RouteTable.Routes.GetVirtualPath(new FakeRequestContext(), routeValues).VirtualPath; var address = new Uri(baseUri, relativeUri); try { using (var webClient = new WebClient()) return(webClient.DownloadString(address)); } catch (WebException ex) { if (!(ex.Response is HttpWebResponse)) { return("<p>{0}</p><pre>{1}</pre>".F(address, HttpUtility.HtmlEncode(ex.ToString()))); } using (TextReader reader = new StreamReader(ex.Response.As <HttpWebResponse>().GetResponseStream())) return(reader.ReadToEnd()); } catch (Exception ex) { return("<p>{0}</p><pre>{1}</pre>".F(address, HttpUtility.HtmlEncode(ex.ToString()))); } }
public static string Url <TController>(this HtmlHelper helper, Expression <Action <TController> > action) where TController : Controller { return(SystemPath.BaseUri() + helper.BuildUrlFromExpression(action)); }