Anthony
Anthony

Reputation: 12407

Extracting Request URI with proxy in between

I am developing a web application which needs to send emails to users instructing them to browse to certain pages which are part of the originating application. My current code to generate the anchor's href is as follows:

String.Format("{0}{1}{2}{3}/{4}",
    Request.Url.Scheme, Uri.SchemeDelimiter, Request.Url.Host, 
    Request.ApplicationPath, path);

The aim was that it would work and link to the correct site, regardless of whether I was running the site on the development server, the test server or the production server. However, there are a couple of drawbacks that I'm looking for some help working around.

  1. Request.Url.Scheme will not work in all cases for us. Our production server requires a https connection. The proxy catches the https connection, decrypts the request and forwards it onto our web server. As such, Request.Url.Scheme will always show http
  2. Request.Url.Host is returning the local server name of our production server; I think this is also related to a proxy issue.
  3. Have read another post which suggests using Request.Headers["host"] instead. Not sure if this would suffer from the same issue.

Does anyone with a bit more knowledge of HTTP/HTTPS, forwarding and ASP.Net's handling of this haz teh codez (or can point me in the right direction)?

Basically, if the user receives the email from the server at dev.example.com using http, the Uri in the email should be http://dev.example.com/page.aspx. If the user is using the production server secure.example.com over https (which is handled by a web proxy) the link should be https://secure.example.com/page.asx.

Upvotes: 3

Views: 972

Answers (1)

Dave Walker
Dave Walker

Reputation: 3523

From my experience dealing with an implementation of Single Sign in our Proxy didnt forward any information on about the original request. We found no way around the https issue which was unfortunate.

I am not 100% but I think the Application request Routing package might allow returned urls inside html to be rewritten to work outside the proxy. E.g. if you return it as http://server.com/page.aspx it may rewrite this as https://server.com/page.aspx. Additionally you can specify rules that will upgrade an http connection to https on the proxy server I believe. So you will have an initial http request that jumps to an https one.

Also you probably want your dev server to work as closely as possible to your prod server for these very issues.

Upvotes: 2

Related Questions