Geeks With Blogs
Bob Palmer's Developer Blog .NET, SQL, and Silverlight Development

At the company where I work, we sometimes have to dynamically build URLs - for example, when a user requests a medical claim PDF, these are generated on the fly and a webservice returns a URL to navigate to.

In our production systems, these are always HTTPS - but in Development, these may be HTTP if an SSL cert is not present.  To work around this, we can dynamically determine if the current page is secure, and adjust our dynamically generated link accordingly, as illustrated below:

string pdfUrl= "mywebserver\\myfile.pdf";

if (Request.IsSecureConnection)
   pdfUrl = "https:\\\\" + pdfUrl;
   pdfUrl = "http:\\\\" + pdfUrl;

Response.Write("<a href=\"" + pdfUrl + "\">Download PDF</a>");

-Bob Palmer

Posted on Tuesday, August 11, 2009 11:36 AM | Back to top

Comments on this post: Determining HTTP or HTTPS in ASP.Net

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © BobPalmer | Powered by: