Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 798191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:55:49+00:00 2026-05-14T22:55:49+00:00

I have an ASP.NET application that uses themes. Let’s pretend I have a theme

  • 0

I have an ASP.NET application that uses themes. Let’s pretend I have a theme named “MySkin”.

I have a page that is in a sub-directory of my application. When I reference a page that uses “MySkin”, I noticed that ASP.NET renders a link element that walks up to the root of the site and then down into the App_Themes directory. Here is an example link element I found in a rendered ASP.NET page:

<link href="../../App_Themes/MySkin/theme.css" type="text/css" rel="stylesheet" />

Is there a reason that the rendered link element does not use the following instead:

<link href="/App_Themes/MySkin/theme.css" type="text/css" rel="stylesheet" />

Is this a browser compatibility issue or is there another reason?

The reason I am asking is because I am rendering my ASP.NET page using Server.Execute and storing the result in a different directory. Because of this, I would prefer to use the second way to reference my theme’s css.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:55:50+00:00Added an answer on May 14, 2026 at 10:55 pm

    According to the built-in internal class PageThemeBuildProvider, asp.net create relative path for css files included in the theme directory

    internal void AddCssFile(VirtualPath virtualPath)
    {
        if (this._cssFileList == null)
        {
            this._cssFileList = new ArrayList();
        }
        this._cssFileList.Add(virtualPath.AppRelativeVirtualPathString);
    }
    

    To overcome your problem you may try using base tag:

    //Add base tag which specifies a base URL for all relative URLs on a page
    System.Web.UI.HtmlControls.HtmlGenericControl g = new System.Web.UI.HtmlControls.HtmlGenericControl("base");
    //Get app root url
    string AppRoot = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "");
    g.Attributes.Add("href",AppRoot);
    Page.Header.Controls.AddAt(0,g);
    

    The bad thing about using this approach is your links will break if the application url gets changed.

    To minimize such change impact, you may use html include in place of the base tag to include a file containing your base tag as follows:

    base.html contains:

    <base href="http://localhost:50897"></base>
    

    this could be created on application begin request:

    bool writeBase = true;
            protected void Application_BeginRequest(object sender, EventArgs e)
            {
                if (writeBase)
                {
                    writeBase = false;
                    //Save it to a location that you can easily reference from saved html pages.                
                    string path = HttpContext.Current.Server.MapPath("~/App_Data/base.html");
                    using (System.IO.TextWriter w = new System.IO.StreamWriter(path, false))
                    {
                        w.Write(string.Format("<base href=\"{0}\"></base>", HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.PathAndQuery, "")));
                        w.Close();
                    }
                }            
            }
    

    and added as a literal control to your aspx :

    //the path here depends on where you are saving executed pages.
    System.Web.UI.LiteralControl l = new LiteralControl("<!--#include virtual=\"base.html\" -->");
    Page.Header.Controls.AddAt(0,l);
    

    saved.html contains:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <!--#include virtual="base.html" -->
    ...
    </head>
     .... 
    </html>
    

    UPDATE:
    This was tested under asp.net development server, if hosted as application under IIS the AppRoot will not be resolved correctly. To get the correct applications absolute url use:

    /// <summary>
    /// Get Applications Absolute Url with a trailing slash appended.
    /// </summary>
    public static string GetApplicationAbsoluteUrl(HttpRequest Request)
    {   
    return VirtualPathUtility.AppendTrailingSlash(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Request.ApplicationPath));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.