Vanity URLs

E

Eric Lemmon

Greetings,

I wrote code to handle vanity URLs, so--for example--the URL
http://localhost/myApp/bsmith.aspx is internally translated to
http://localhost/myApp/Support/UserPage.aspx?user=bsmith.

The problem is that whenever I access the vanity URL,
http://localhost/myApp/bsmith.aspx, the page shows without any CSS
styles...quite ugly. However, when I get to the page directly using its
actual address, http://localhost/myApp/Support/UserPage.aspx?user=bsmith, it
displays fine.

Does anyone know what I'm doing wrong? (The Global.asax.vb code is below)

Thank you!

Eric


'\\\
' NOTE: This code assumes "Imports System.IO"

Sub Application_BeginRequest(ByVal sender As Object, _
ByVal e As EventArgs)
' Fires at the beginning of each request
Dim strPageOwner As String
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path.ToLower
With strCurrentPath

' Make sure the request is for the vanity URL, where it is an
' aspx page in the root directory, and it is not Default.aspx.

If .IndexOf("default.aspx") = -1 AndAlso _
.IndexOf("/products/") = -1 AndAlso _
.IndexOf("/secure/") = -1 AndAlso _
.IndexOf("/support/") = -1 AndAlso _
.IndexOf("/about/") = -1 Then

strCustomPath = String.Format( _
"/myApp/Support/UserPage.aspx?user={0}", _
Path.GetFileNameWithoutExtension(Request.Path))

Context.RewritePath(strCustomPath)

End If
End With

End Sub
'///
 
J

Janaka

Eric

I'm guessing that your css is not being referenced because the page cannot
find the relative path to the stylesheet.
Try making your stylesheet reference absolute such as <link
href="/styles.css" type="text/css" rel="stylesheet">

Janaka
 
E

Eric Lemmon

Thanks for the quick reply, Janaka.

I looked over the the <link> tag a dozen times, both in the IDE and in the
rendered source code...but you're right!

It seems that using the vanity URL on the root directory is what threw me.
Because the URL was redirected to a subdirectory, the <link> tag no longer
applied. All I did to fix this was add an extra <link> tag in the
UserPage.aspx HTML source code that omitted the "../", directing the <link>
to the subdirectory instead of up one level

In other words, I changed my links from this:

<LINK href="../scripts/Styles.css" type="text/css" rel="stylesheet">
<LINK href="../scripts/Menus.css" type="text/css" rel="stylesheet">

to this:

<LINK href="../scripts/Styles.css" type="text/css" rel="stylesheet">
<LINK href="../scripts/Menus.css" type="text/css" rel="stylesheet">
<LINK href="scripts/Styles.css" type="text/css" rel="stylesheet">
<LINK href="scripts/Menus.css" type="text/css" rel="stylesheet">

A word of caution to anyone else trying this, *everything* is thrown off if
you redirect the context to a different subdirectory, including all your
links, image src, etc. It's much easier (and *much* less messy) to just
have the destination page in the same directory as your vanity URL.

Thanks again,

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top