开发者

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://lo开发者_如何学Ccalhost:1807/WebSite/calculator.aspx"


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


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.


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

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


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.


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"


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜