URL Rewrite and ASP.NET 2.0 Themes (/ in path css)

Jan 13, 2009 at 10:42 AM
Hi there

Thanks for the ISAPI Rewrite Filter. It works great and I can set the theme according to a value from the page in the db.

The problem is that as soon as I include a / in the imaginary path the page is found but the css form the themes are not applied.

This is what I use
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
IsapiRewrite4.ini

RewriteRule \w?/page(\d+) /page.aspx?page_id=$1 [U]

I am looking for "page" followed by some Digits in the URL.

It works great with the following examples (concerning the ASP.NET Themes)

www.schreinerei-pavoni.ch/page3
www.schreinerei-pavoni.ch/page3anything 
www.schreinerei-pavoni.ch/page3+any+thing
www.schreinerei-pavoni.ch/page3anything.httttmmmmllll

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
As soon as I do something like www.schreinerei-pavoni.ch/page3anything/something it still works but the css files are not applied (or found). If I look at the source code of a page rewritten like this


www.schreinerei-pavoni.ch/page3anything or
www.schreinerei-pavoni.ch/page3/anything (with a /)

The source code looks exactely the same 

<link href="App_Themes/oneblock/div.css" type="text/css" rel="stylesheet" />
<link href="App_Themes/oneblock/StyleSheet.css" type="text/css" rel="stylesheet" />

The page is still found but no CSS applied.

Now based on some DB entry from page 3 I set different Themes from the App_Themes folder

I use the Page_PreInit to set the Theme (I use a page.master)

 

Protected

 

Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit 
Dim myPageContent As New myCMS.DAL.Pages.Content
Dim
myDataset As DataSet
Dim page_id As String = Request("page_id")
Dim page_language As String 

'Settting the Language
I
f Not Request.QueryString("Language") Is Nothing Then
page_language = Request.QueryString("Language")
Session(
"Language") = Request.QueryString("Language")
ElseIf Session("Language") Is Nothing Then
page_language = System.Configuration.ConfigurationManager.AppSettings("DefaultLanguage")
Else
page_language = Session("Language")
End If

 

 

 

 

'Setting the Theme (Layout)
myDataset = myPageContent.GetPageContentByPageIDAndLanguage(page_id, page_language)
If myDataset.Tables(0).Rows.Count > 0 Then
Page.Theme = myDataset.Tables(0).Rows(0).Item("page_master").ToString
Else
Page.Theme = System.Configuration.ConfigurationManager.AppSettings("DefaultTheme")
End If
End Sub

 

 

 

 

I would assume that the page no mather if I enter a / or not is redirected to page.aspx?page_id=3 so I can not figure out why whithout slash it works but breaks when using a slash in the path.

Any idea 

Regards Markus


 

 

Jan 13, 2009 at 11:07 AM
Some more testing that might give a clue

I loaded www.schreinerei-pavoni.ch/page3anything which works fine and used IE and saved the page with all files. .css are there

I loaded www.schreinerei-pavoni.ch/page3/anyting which does not work and used IE and seved the page with all files

The two files div.css and stylesheet.css are saved as div.htm and stylesheet.htm (strange)

Within the .htm files I get

UNKNOWN {

 

}

UNKNOWN {

 

}

UNKNOWN {

 

}

This adds to my confusion but might help someone with more brains then I have.

Regards Markus

Jan 13, 2009 at 11:21 AM
Looking at the temp internet files I found at least the reason for the css not working

path to css is

www.schreinerei-pavoni.ch/App_Themes/ when using www.schreinerei-pavoni.ch/page3anything

but

www.schreinerei-pavoni.ch/seite3/App_Themes when using www.schreinerei-pavoni.ch/page3/anything

Does anyone know an easy way to get the App_Themes to work allways from the root?

Including the CSS in the masterpage does not work since I need to load different .css files according to theme

Regards Markus
Jan 13, 2009 at 1:40 PM
There seem to be simple solutions

http://www.aspcode.net/Master-pages-themes-and-url-rewriting.aspx

I just don't know how to apply them to the IsapiRewrite4.ini

Any help is appreciated

Markus
Jan 15, 2009 at 10:40 AM
Solved

I just added 

 

<base href="www.schreinerei-pavoni.ch/" />

to the head of the master.page and now it works

Regards markus