code_junkie

Paths in master pages

Nov 10th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
  2.  
  3. <link href="Content/Site.css" rel="stylesheet" type="text/css" />
  4.  
  5. <script src="../../Content/menu.js" type="text/javascript"></script>
  6.  
  7. <script src="<%= ResolveClientUrl("~/Content/menu.js") %>" type="text/javascript"></script>
  8.  
  9. public static string ResolveUrl(this HtmlHelper helper, string virtualUrl)
  10. {
  11. HttpContextBase ctx = helper.ViewContext.HttpContext;
  12. string result = virtualUrl;
  13.  
  14. if (virtualUrl.StartsWith("~/"))
  15. {
  16. virtualUrl = virtualUrl.Remove(0, 2);
  17.  
  18. //get the site root
  19. string siteRoot = ctx.Request.ApplicationPath;
  20.  
  21. if (!siteRoot.EndsWith("/"))
  22. siteRoot += "/";
  23.  
  24. result = siteRoot + virtualUrl;
  25. }
  26. return result;
  27. }
  28.  
  29. <script type="text/javascript" src="<%= Html.ResolveUrl("~/Content/menu.js")%>"></script>
  30.  
  31. <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
Add Comment
Please, Sign In to add comment