Company      |       Articles & Research      |      Services      |      Software      |      Contact

Determine If SharePoint Context Is Secure (SSL)

So I have two types of SharePoint environments, one is SSL enabled and another is not. Both are extended to use the same content databases, so have the same presentation layer content. This is a pretty common situation with SharePoint.
When writing WebParts for my environment, it was important that I compensated by writing a small method that would determine whether the HTTP context that SharePoint was running under was using a secure connection. In case you have to do the same thing, you can write method using the IsSecureConnection in order to determine if the HTTP connection uses secure sockets. You can either orchestrate the user to a SSL enabled sites if it is true:

C#:
  1. if (!HttpContext.Current.Request.IsSecureConnection)
  2. {
  3. string newUrl = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
  4. Response.Redirect(newUrl, true);
  5. return;
  6. }

or you can write an error message if it is false:

C#:
  1. if(HttpContext.Current.Request.IsSecureConnection == false)
  2. {
  3. string message = "You should use HTTPS to avoid sending
  4. passwords in clear text";
  5. HttpContext.Current.Trace.Warn(message);
  6. throw new InvalidOperationException(message);
  7. }

share save 171 16 Determine If SharePoint Context Is Secure (SSL)

Related posts:

  1. Return LCID From HTTPContext
  2. Portal Context, User Profile Manager, and User Profile
  3. Determine If There Are Files And Folders In SharePoint Document Library
  4. Determine If SharePoint List Column Exists In C#
  5. Determine Referenced Assemblies and Assembly Load State

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment