More in this section

Forums / General Discussions / How to tackle url/href/css/js when in virtual directory?

How to tackle url/href/css/js when in virtual directory?

4 posts, 0 answered
  1. Saad
    Saad avatar
    98 posts
    10 Oct 2008
    24 Aug 2011
    Link to this post
    I ran into a problem where I needed to deploy Sitefinity website in a virtual directory. I came to know that my stylesheet/js links doesnt work with following:

    <head runat="server">
    <link href="/Common/CSS/Default_en_gb.css" rel="stylesheet" type="text/css" />
    <script src="/Common/JS/myJSFile.js" type="text/javascript"></script>

    I cant use <%= BaseUrl %> to manage the urls when as a independent website or in virtual directory.

    Please suggest.

    Thank you
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    18 Jul 2012
    24 Aug 2011
    Link to this post
    Have you tried using ResolveUrl()?

    Something like this should work:

    <link href="<%= ResolveUrl("~/Common/CSS/Default_en_gb.css") %>" rel="stylesheet" type="text/css" />

    There is also VirtualPathUtility.ToAbsolute(), although I have never tried it.

    Finally you can also use the Sitefinity controls for this: Sitefinity Designer's Guide: Including JavaScript and CSS Resources

    hope this is helpful!
  3. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    18 Sep 2017
    29 Aug 2011
    Link to this post
    Hi Saad,

    In addition to the previous suggestions you can try to put the path to css or .js file in the browser and see if they are accessible. If you are forbidden to view them check if you have proper permissions on the folders where css and .js files reside.

    Best wishes,
    Stanislav Velikov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  4. Saad
    Saad avatar
    98 posts
    10 Oct 2008
    01 Sep 2011
    Link to this post
    Thanks SelAromDotNet for the suggestion!

    I went deep into the control that Sitefinity offers and tried that way. I used ResourceLinks control to have my stylesheets referenced to my masterpages correctly.

    <sitefinity:ResourceLinks id="resourcesLinks" runat="server">

    Then I added resources on runtime as needed (for English and Arabic):

    Telerik.Sitefinity.Web.UI.ResourceFile resource = new Telerik.Sitefinity.Web.UI.ResourceFile();
                resource.Name = "Styles/Default_" +
                                (Request.Url.ToString().ToLower().Contains("/ar/") ? "ar_ae" : "en_gb") +

    Thanks very much for the guidance guys.
4 posts, 0 answered