tags:

views:

47

answers:

2
+1  Q: 

Port in the URL

Hi,

I've got a web app that I deploy to several applications like so-

https://customerinternaldomain.com/thewebapp

There are a lot links that pop open windows. In the past I was using the following to determine the url of the window to pop.

string appPath = this.Request.ApplicationPath;
      if ( !appPath.EndsWith ( "/" ) )
        appPath += "/";
      string sURL = this.Request.Url.Scheme + "://" + this.Request.Url.Authority
        + appPath 

Then I just append on the path to the window page that I want to open like so

appPath += "somefolder/window.aspx"

One of our installations just moved to a non standard port, something like 20055.

So I've fooled around with coming up with a clean full proof way to make sure that the port is inserted in the path, but since the webapp is mapped to https://internaldomain.com/thewebapp instead of just https://internaldomain.com/ I'm not seeing a clean way using Request server variables to do this. Sure I can hack and slash with splits or something, or store the base web path in a config file that gets read. Just wondering if anyone had a clean way of doing this. Assuming something obvious that I'm just missing, so I figured I'd put the best and brightest on it.

Thanks for any help you provide, I know time is valuable. I appreciate it.

+2  A: 
.Replace(".com", ".com:20055")
Filip Ekberg
Ha. yeah I could do that, but the internal domains don't always end with .com, else I would have done this in a heart beat. +1 for simplicity that would have worked given what I told you.
infocyde
Well, you could always use a regex to determen the end of the domain. :) There's a Regex.Replace you know!
Filip Ekberg
+1  A: 

I don't have access to an ASP server or Visual Studio right now to get the details, but I know you can get the domain name, and the URL path from it, from the Request.Url object. Quick search tells me it's Request.Url.Host to get the internaldomain.com part.

So, you would just have to append the port to this, and piece it all together.

So, it'd be something like

scheme + "://" + host + ":" + port "/" + currentPath + "/" + appPath

As I said, can't check the specifics right now, but I know the Request object will let you access all these parts. The port you may have to store somewhere, if you're going from one port to another.

Slokun
I think you are on the right track. I found the answer here in stack overflow http://stackoverflow.com/questions/689678/request-url-host-and-applicationpath-in-one-call I used MartinHN's solution (about half way down the page). I didn't think it would work but it does.
infocyde