Wednesday, February 4, 2015

Basic rules for using ResolveClientUrl in master pages (ASP.NET)

When writing ASP.NET Web Forms, the basic rules for using ResolveClientUrl in master pages are:
<img src="<%= ResolveClientUrl("~/x/resource.jpg")%>" />
<script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
If you want to use ResolveClientUrl in the master page <head> section for script tags:
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
   <script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
</asp:PlaceHolder>

You do not need to use ResolveClientUrl for CSS link elements in the <head> section (they will automatically be resolved by ASP.NET).

No comments:

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...