GurdeepS
GurdeepS

Reputation: 67223

Theme is referenced but not used, at runtime

I have a website which uses themes. Depending on the url (if it is A.something.com or B.something.com, where A and B represent clients), I will load a different theme. The intention is to use one codebase for different clients. I have an app_themes folder, several themes inside, for different clients, and different CSS files for each theme (for business reasons the CSS file is the same for each theme, but duplicated). So my code looks like this:

Public Overrides Property StyleSheetTheme() As String

    Get
        Dim myHost As String = Request.Url.Host
        Return myHost
    End Get
    Set(ByVal value As String)
    End Set
End Property







Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

    If Request.Url.Host.Contains("Savills") Then
        Page.Theme = "Savills"
    ElseIf Request.Url.Host.Contains("localhost") Then
        Page.Theme = "localhost"
    ElseIf Request.Url.Host.Contains("test.concepglobal.com") Then
        Page.Theme = "test.concepglobal.com"
    ElseIf Request.Url.Host.Contains("concepglobal") Then
        Page.Theme = "concepglobal"

    End If



End Sub

My app_themes folder structure:

App_Themes:

localhost:

Default.css

Savills

Savills.css

However, everytime I load the site, the css is not picked up. So I don't get the h1 style I designed in the css (it is in there), but only the graphics specified in the aspx page.

My source when running the site:

(loading the site at that url).

Confusingly, there is another link to the same css:

What am I doing wrong?

Thanks

Upvotes: 0

Views: 280

Answers (2)

Keltex
Keltex

Reputation: 26426

Instead of doing this though code, you can specify the theme used by the application (or a folder) through your web.config:

<system.web>
    <pages theme="concepglobal"></pages>
</system.web>

This assumes you have different web.config files for each client.

Upvotes: 0

DOK
DOK

Reputation: 32841

Is this occurring only when you run the code from within Visual Studio?

When running in ASP.Net Development Server, the styles in App_Themes won't be used on any unauthenticated page (such as Login.aspx or ForgotPassword.aspx). That's because the user doesn't have browse permissions on that folder yet, or the App_Themes folder lacks browsing permissions. Apparently, IIS handles this but Cassini doesn't.

Try adding this to web.config to let Themes and styles work before authentication.

<location path="App_Themes">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>

Or, if possible, switch to running the app on IIS on your machine.

Upvotes: 2

Related Questions