asp.net - What is the best way to determine URL for local/staging/production? -


The url for local testing is like this:

For staging, the app is in the virtual directory:

For production, this is the root cause

However, sometimes we need to redirect to a particular directory. We do not always know where we are.

So, how do I do a redirect to say /subdir1/mypage.aspx?

More info

I ignored one important item. This URL is sent back to the browser so that some JavaScript code can redirect. (Weird, I know). Therefore, a regular ResolveUrl ("~ / / pagename.aspx") will not complete the information ...

UPDATE 2 I ended up with the following, which seems to be working across the board In ... this looks a bit ugly.

  stringbuilder buildUrl = new string builder (@ "http: //"); BuildUrl.Append (Request.Url.Host); If (Request.Url.Port! = 80) {buildUrl.Append (":"); BuildUrl.Append (Request.Url.Port.ToString ()); } BuildUrl.Append (this.ResolveUrl ("~ / Pages / Customers.aspx")); BuildUrl.Append (string.format ("? Account id = {0} and tab name = tab2 and primary custom ID = {1}", acct, CTID);  

When paths are isolated between different environments, and you There is no discretion in this situation, it is time to start puttin 'path in web.config

This is not the treatment of an incompatible file path, but it is your code And you will not have to worry about having "tell me where I am."


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -