I'll try to keep this brief. Can anyone help me to understand why IIS cannot use the Request.ApplicationPath the same way in a root website as it does in a virtual directory? My reference is to the latest I Buy Spy portal code, but is applicable to any code of this type. This also applies to the use of the tilde "~" in ASP.NET code. The tilde should represent the application path in ASP.NET code so these should be interchangeable. If you are in a virtual directory: http://portal.ragingfrog.com/portal - Request.ApplicationPath = /portal In the root site: http://portal.ragingfrog.com - Request.ApplicationPath = /
This in itself causes problems, but can be handled. You'd think IIS would be able to handle it though. If you look at the site links above and hover over the tabs on the page you will see this difference in URL generation using the Request.ApplicationPath. It is the EXACT same code deployed to both a virtual directory and the root. One works, one does not. This is the code: *Extra spaces have been added to prevent HTML rendering in this message*
That said, I cant see exactly what your problem is. You seem to need something a little more flexible, like the root & the application path together. You might find the URL object more flexible for your needs.
Try using the Request.URL object, its very flexible in breaking down the actual request location. Try this:
Request.Url.GetLeftPart(UriPartial.Authority)
-- Regards
John Timney (Microsoft ASP.NET MVP) ---------------------------------------------- <shameless_author_plug> Professional Windows Forms ISBN: 1861005547 Professional JSP ISBN: 1861003625 Beginning JSP Web Development ISBN: 1861002092 </shameless_author_plug> ----------------------------------------------
> I'll try to keep this brief. > Can anyone help me to understand why IIS cannot use the > Request.ApplicationPath the same way in a root website as it does in a > virtual directory? My reference is to the latest I Buy Spy portal code, but > is applicable to any code of this type. This also applies to the use of the > tilde "~" in ASP.NET code. The tilde should represent the application path > in ASP.NET code so these should be interchangeable. > If you are in a virtual directory: > http://portal.ragingfrog.com/portal - Request.ApplicationPath = /portal > In the root site: > http://portal.ragingfrog.com - Request.ApplicationPath = /
> This in itself causes problems, but can be handled. You'd think IIS would > be able to handle it though. If you look at the site links above and hover > over the tabs on the page you will see this difference in URL generation > using the Request.ApplicationPath. It is the EXACT same code deployed to > both a virtual directory and the root. One works, one does not. > This is the code: > *Extra spaces have been added to prevent HTML rendering in this message*
Yes, I'll have to look at that. The thing is, that code came straight out of the I Buy Spy portal site from Microsoft. I'm trying to figure out if their code doesn't work, or if it's me. I'll give your suggestion a shot.
> That said, I cant see exactly what your problem is. You seem to need > something a little more flexible, like the root & the application path > together. You might find the URL object more flexible for your needs.
> Try using the Request.URL object, its very flexible in breaking down the > actual request location. Try this:
> Request.Url.GetLeftPart(UriPartial.Authority)
> -- > Regards
> John Timney (Microsoft ASP.NET MVP) > ---------------------------------------------- > <shameless_author_plug> > Professional Windows Forms > ISBN: 1861005547 > Professional JSP > ISBN: 1861003625 > Beginning JSP Web Development > ISBN: 1861002092 > </shameless_author_plug> > ----------------------------------------------
> "Brock" <br...@vrsdata.com> wrote in message > news:uGlhOvTyBHA.2324@tkmsftngp02... > > I'll try to keep this brief. > > Can anyone help me to understand why IIS cannot use the > > Request.ApplicationPath the same way in a root website as it does in a > > virtual directory? My reference is to the latest I Buy Spy portal code, > but > > is applicable to any code of this type. This also applies to the use of > the > > tilde "~" in ASP.NET code. The tilde should represent the application > path > > in ASP.NET code so these should be interchangeable. > > If you are in a virtual directory: > > http://portal.ragingfrog.com/portal - Request.ApplicationPath = /portal > > In the root site: > > http://portal.ragingfrog.com - Request.ApplicationPath = /
> > This in itself causes problems, but can be handled. You'd think IIS would > > be able to handle it though. If you look at the site links above and > hover > > over the tabs on the page you will see this difference in URL generation > > using the Request.ApplicationPath. It is the EXACT same code deployed to > > both a virtual directory and the root. One works, one does not. > > This is the code: > > *Extra spaces have been added to prevent HTML rendering in this message*
The problem is this. When deployed to a virtual directory, I need the root/virtual dir. When deployed to the root, I need just the root. That is where the tilde and the ApplicationPath are having problems. Neither one of them works in BOTH scenarios.
> That said, I cant see exactly what your problem is. You seem to need > something a little more flexible, like the root & the application path > together. You might find the URL object more flexible for your needs.
> Try using the Request.URL object, its very flexible in breaking down the > actual request location. Try this:
> Request.Url.GetLeftPart(UriPartial.Authority)
> -- > Regards
> John Timney (Microsoft ASP.NET MVP) > ---------------------------------------------- > <shameless_author_plug> > Professional Windows Forms > ISBN: 1861005547 > Professional JSP > ISBN: 1861003625 > Beginning JSP Web Development > ISBN: 1861002092 > </shameless_author_plug> > ----------------------------------------------
> "Brock" <br...@vrsdata.com> wrote in message > news:uGlhOvTyBHA.2324@tkmsftngp02... > > I'll try to keep this brief. > > Can anyone help me to understand why IIS cannot use the > > Request.ApplicationPath the same way in a root website as it does in a > > virtual directory? My reference is to the latest I Buy Spy portal code, > but > > is applicable to any code of this type. This also applies to the use of > the > > tilde "~" in ASP.NET code. The tilde should represent the application > path > > in ASP.NET code so these should be interchangeable. > > If you are in a virtual directory: > > http://portal.ragingfrog.com/portal - Request.ApplicationPath = /portal > > In the root site: > > http://portal.ragingfrog.com - Request.ApplicationPath = /
> > This in itself causes problems, but can be handled. You'd think IIS would > > be able to handle it though. If you look at the site links above and > hover > > over the tabs on the page you will see this difference in URL generation > > using the Request.ApplicationPath. It is the EXACT same code deployed to > > both a virtual directory and the root. One works, one does not. > > This is the code: > > *Extra spaces have been added to prevent HTML rendering in this message*
I have a 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 <%= Request.ApplicationPath%> with <%= Application("AppPath")%> If you have any other suggextions, let me know.
> I'll try to keep this brief. > Can anyone help me to understand why IIS cannot use the > Request.ApplicationPath the same way in a root website as it does in a > virtual directory? My reference is to the latest I Buy Spy portal code, but > is applicable to any code of this type. This also applies to the use of the > tilde "~" in ASP.NET code. The tilde should represent the application path > in ASP.NET code so these should be interchangeable. > If you are in a virtual directory: > http://portal.ragingfrog.com/portal - Request.ApplicationPath = /portal > In the root site: > http://portal.ragingfrog.com - Request.ApplicationPath = /
> This in itself causes problems, but can be handled. You'd think IIS would > be able to handle it though. If you look at the site links above and hover > over the tabs on the page you will see this difference in URL generation > using the Request.ApplicationPath. It is the EXACT same code deployed to > both a virtual directory and the root. One works, one does not. > This is the code: > *Extra spaces have been added to prevent HTML rendering in this message*