Chad
Chad

Reputation: 24699

How do I get the dynamic port at run time used by visual studio? e.g, http://localhost:1807

I am using Google Checkout and I could like to create an absolute URL for returning to our web site to edit he cart and I would like the code to work in debug mode as well as production mode.

Req.EditCartUrl = "http://localhost:1807/WebSite/calculator.aspx"

Upvotes: 1

Views: 787

Answers (6)

Chad
Chad

Reputation: 24699

Many good suggestions.

This will work, too:

Public Shared Function WebsiteBaseUrl() As String

    Dim RequestObject As System.Web.HttpRequest = HttpContext.Current.Request

    Return "http://" & RequestObject.Url.Host & ":" & _
                       RequestObject.Url.Port & "/" & _
                       RequestObject.Url.Segments(1)
End Function

Upvotes: 0

FiveTools
FiveTools

Reputation: 6030

Req.EditCartUrl = VirtualPathUtility.ToAbsolute("~/calculator.aspx");

Upvotes: 1

bkaid
bkaid

Reputation: 52093

You could assign it a specific port and then you would know what it is. You should be able to get it from Request.Url.Port though. You should try and use relative urls such as

Req.EditCartUrl = "~/calculator.aspx"

Upvotes: 1

James Campbell
James Campbell

Reputation: 5087

The location for what you are looking for is in the solution file of your solution, open the sln(send to notepad) you will see what I mean, you can hard code the port if you are using the built in webserver(Casini) or you can port it all to your local IIS, which is what I do.

This is the value in the sln file: VWDPort = "YOURPORTNUMBER HERE"

You can also make the change as stated in Luhmann's answer, but I find that by doing it that way, sometimes causes the port to change.It is strange quark on my machine at least.

Upvotes: 1

Luhmann
Luhmann

Reputation: 3890

You could run the site in IIS eliminating the port issue:

alt text http://devtalk.dk/content/binary/iisserver.png

Upvotes: 1

Ian Mercer
Ian Mercer

Reputation: 39317

You can use the server variables http://msdn.microsoft.com/en-us/library/ms524602.aspx to get the port (and much more) but it would be easier just to host in IIS on your development box and fix the port to 80.

Upvotes: 1

Related Questions