Router Port Forwarding and HttpContext.Current.Request.Url

Here is the script. We have a router that sends requests for our different test sites. For example, http://www.ourSite.com:8051 should be forwarded from a router to a web server located on port 80. The websites under test are virtual directories of one website running on IIS6 (Windows Server 2003).

Part of our application sends emails that use the base url to create some links in the application. Here begins the base url created in our application:

siteBaseUrl = string.Format("{0}://{1}{2}",
                HttpContext.Current.Request.Url.Scheme,
                HttpContext.Current.Request.Url.Authority,
                HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));

So, let's say one of our test sites looks like this: http://www.ourSite.com:8051/client1 . I would expect siteBaseUrl to look like this: http://www.ourSite.com:8051/client1 , when in fact it looks like this: http://www.ourSite.com/client1 (I tried to find such a question in StackOverflow, but didn’t find it. Maybe I didn’t look for the right keywords, or I need more coffee. The question would be quite helpful.

+3
source share
2 answers

HttpContext.Current.Request.Url , IIS, URL- . Host HTTP-.

siteBaseUrl = string.Format("{0}://{1}{2}",
                HttpContext.Current.Request.Url.Scheme,
                HttpContext.Current.Request.Headers["host"],
                HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));
+5

, javascript URL- .

0

Source: https://habr.com/ru/post/1713184/


All Articles