When I deploy ibuyspy to a root web, how do I get my links to...

Expand / Collapse
 
     

When I deploy ibuyspy to a root web, how do I get my links to work correctly (Request.ApplicationPath doesn't work)?


This is the nature of how ibuyspy works.  You are suppose to deploy it into a subdirectory.  However, if you must put it onto your root, you must modify your code by following below:
 

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#): 

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.





Add Your Comments


Name: *
Email Address:
Web Address:
Verification Code:
*
 

Details
Last Modified:11/30/2008 9:41 PM
Last Modified By: Mark
Type: Error Message
Article not rated yet.
Article has been viewed 617 times.
Options