I got this from http://aspsmith.com/DesktopDefault.aspx?tabindex=2&tabid=32.
Another thing you can do is replace all the <%= Application("AppPath")%> calls with the correct relative path.
ie. If you have a hyperlink that reads <%= Application("AppPath")%>/portal.css you could get there by using ../portal.css from one of the inner folders etc.
Those hyperlinks that are resolving different tabs for the Desktop Default don't really need the <%= Application("AppPath")%> portion. You can just trim those to DesktopDefault.aspx?tabindex=1, 2, 3, etc.
This problem is happening because if you deploy to a root web you are not in a virtual directory. Try doing a response.write(Application("AppPath")) and see what you get.
You will probably get a null string. This is what you need to fix.
BUG FIX: When I deploy to a root web, how do I get my links to work correctly (Request.ApplicationPath doesn't work)?
A: Answer from Brock on aspngibuyspy list at ASPFriends.com:
I apologize for the last post, it wasn't quite tested very well. This is a
new solution. I might be able to clean it up more with a little more
research, but this works for both virtual directories and root sites. The
If statement checks on every request, but the code should only process once.
I put this code in the Application_BeginRequest:
' Build the Application Path
If Application("AppPath") = Nothing Then
Dim sAbsUri As String = Request.Url.AbsoluteUri
Dim sRawUrl As String = Request.RawUrl
If Request.ApplicationPath = "/" Then
Application("AppPath") = Left(sAbsUri, Len(sAbsUri) - Len(sRawUrl))
Else
Application("AppPath") = Left(sAbsUri, Len(sAbsUri) - Len(sRawUrl)) &
Request.ApplicationPath
End If
End If
Then just replace all the script calls for
with <%= Application("AppPath")%>
--------------------------------------------------------------------------------
Another solution (C#):
I wrote a piece of
C# code yesterday following the same strategy which was
in VB on your site to fix this issue and it works fine.
In Global.ascx:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
....
// Build the Application Path to workaround Web root reference issue
if (Application["AppPath"] == null)
{
String sAbsUri = Request.Url.AbsoluteUri;
String sRawUrl = Request.RawUrl;
if (Request.ApplicationPath == "/")
Application["AppPath"]= sAbsUri.Substring(0,sAbsUri.Length -
sRawUrl.Length);
else
Application["AppPath"] = sAbsUri.Substring(0,sAbsUri.Length -
sRawUrl.Length) + Request.ApplicationPath;
}
......
}
Then replace all "Request.Applicationpath" in *.aspx and *.ascx with
Application["AppPath"]
replece all "~/..." in *.cs with Application["AppPath"] +"/..."
For example:
Replace redirect("~/admin/tablayout.aspx) with
redirect(Application["AppPath"]+"/admin/tablayout.aspx)
It works for both root web and virtual directory.
Jerome Xie