I use this simple function in my app anytime I need to reference the base path. I stick it into my base control/page/etc. This will even take into account for varying ports like you get with VWDE
Public Shared ReadOnly Property UrlBase() As String
Get
Dim _return As String = ""
If HttpContext.Current.Request.Url.Port = 80 Then
_return = "http://" & HttpContext.Current.Request.Url.Host & HttpContext.Current.Request.ApplicationPath
Else
_return = "http://" & HttpContext.Current.Request.Url.Host & ":" & HttpContext.Current.Request.Url.Port & HttpContext.Current.Request.ApplicationPath
End If
If _return.EndsWith("/") Then
_return = _return.Substring(0, _return.Length - 1)
End If
Return _return
End Get
End Property
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
You can use the code that Curt provided or what I did was I created a variable for the base path in my web.config. So in my local config i have it set to
http://localhost/appname/, and on the remote server i have it set to the domain (ie
http://www.yourdomain.com/). So everywhere you need to create an absolute path just prepend that variable.
jmun
Member
1 Points
17 Posts
how to change application path in visual studio web dev express edition
Jul 27, 2007 01:47 AM|LINK
When I run my application locally the path looks like this:
http://localhost:1234/myapp/
This causes a problem with my links because on my hosting server it doesnt have the myapp directory
Is there any way to configure visual studio express edition to not use the app name like this?
http://localhost:1234/
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: how to change application path in visual studio web dev express edition
Jul 27, 2007 01:49 AM|LINK
it shouldnt' matter... you should never have it hard-coded in your site.
Where does this cause you an issue?
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
jmun
Member
1 Points
17 Posts
Re: how to change application path in visual studio web dev express edition
Jul 27, 2007 02:02 AM|LINK
i hard code links in my master page because i have pages that use the master page inside subdirectories
so in my master page i build my links like this:
Dim base As String = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ApplicationPath & "/"
so im trying to get rid of the Request.ApplicationPath & "/" so that it works the same on my local on remote server
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: how to change application path in visual studio web dev express edition
Jul 27, 2007 12:36 PM|LINK
I use this simple function in my app anytime I need to reference the base path. I stick it into my base control/page/etc. This will even take into account for varying ports like you get with VWDE
Public Shared ReadOnly Property UrlBase() As String
Get
Dim _return As String = ""
If HttpContext.Current.Request.Url.Port = 80 Then
_return = "http://" & HttpContext.Current.Request.Url.Host & HttpContext.Current.Request.ApplicationPath
Else
_return = "http://" & HttpContext.Current.Request.Url.Host & ":" & HttpContext.Current.Request.Url.Port & HttpContext.Current.Request.ApplicationPath
End If
If _return.EndsWith("/") Then
_return = _return.Substring(0, _return.Length - 1)
End If
Return _return
End Get
End Property
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
AmeetBala
Member
4 Points
2 Posts
Re: how to change application path in visual studio web dev express edition
Aug 22, 2007 01:31 AM|LINK
I'm facing a similar problem
On the local machine my application path has the extra /myapp path which does not exist on the server where hosted.
This causes all my links to fail. For example:
<link rel="stylesheet" href="/stylesheets/stylesheet.css" type="text/css" />
This works fine on the server but fails when I run it locally.
When I hard code /myapp/ or remove the initial root '/' in the path it works fine locally but fails on the server. For example
<
link rel="stylesheet" href="/myapp/stylesheets/stylesheet.css" type="text/css" /><link rel="stylesheet" href="stylesheets/stylesheet.css" type="text/css" />
How do I change the app path on the local machine to not have myapp as the root folder.
It seems like a silly issue but has eaten up a lot of my time. I would much appreciate a resolution.
Thanks.
jmun
Member
1 Points
17 Posts
Re: how to change application path in visual studio web dev express edition
Aug 22, 2007 05:02 AM|LINK
You can use the code that Curt provided or what I did was I created a variable for the base path in my web.config. So in my local config i have it set to http://localhost/appname/, and on the remote server i have it set to the domain (ie http://www.yourdomain.com/). So everywhere you need to create an absolute path just prepend that variable.
hope this helps