+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / SSL redirects custom Http Module

SSL redirects custom Http Module

15 posts, 0 answered
  1. Gaurav Mehta
    Gaurav Mehta avatar
    43 posts
    Registered:
    09 Dec 2009
    10 Dec 2009
    Link to this post
    Hi,
    I m trying to implement custom HTTP module for SSL Redirect using following code:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Web; 
    namespace Sitefinity.Samples 
        /// <summary> 
        /// Summary description for Https301 
        /// </summary> 
        public class Https301 : CmsHttpModule 
        { 
            protected override void ProcessSslRedirect(HttpContext context, ICmsUrlContext url) 
            { 
                if (UrlHelper.SslRedirection != SslRedirection.None) 
                { 
                    if (url.RequireSSL && !context.Request.IsSecureConnection) 
                    { 
                        this.RedirectToHttps(); 
                        return
                    } 
                    else if (UrlHelper.SslRedirection == SslRedirection.Both && !url.RequireSSL && context.Request.IsSecureConnection) 
                    { 
                        this.RedirectToHttp(); 
                        return
                    } 
                } 
            } 
            private void RedirectToHttps() 
            { 
                HttpContext context = HttpContext.Current; 
                //context.Response.StatusCode =..... 
                context.Response.Redirect(context.Request.Url.AbsoluteUri.Replace("http://""https://"), true); 
            } 
      
            private void RedirectToHttp() 
            { 
                HttpContext context = HttpContext.Current; 
                //context.Response.StatusCode =..... 
                context.Response.Redirect(context.Request.Url.AbsoluteUri.Replace("https://""http://"), true); 
            } 
        } 
     

    System details:

    OS: Windows XP Professional
    VS.Net 2005
    .Net Framework: 3.0

    I have create new class library project and added above code into class.
    Added reference to Telerik.Cms.dll
    I am having following problems while preforming solution build:

    1) The type or namespace name 'Linq' does not exist in the namespace 'System'
       I have removed  "System.Linq" namespace. Is it ok ?
    2) The type or namespace name 'ICmsUrlContext' could not be found
    3) I did not get SslRedirection in UrlHelper class

    I m sure that I am missing some reference here. Please let me if anyone has idea about this.

    Regards,
    Gaurav



  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    10 Dec 2009
    Link to this post
    Hi Gaurav Mehta,

    1.You can remove the System.Linq, because it is not used in the code.

    2. The namespace of ICmsUrlContext  is Telerik.Cms.Web. Try using Telerik.Cms.Web.ICmsUrlContext

    3. SslRedirection is implemented from Sitefinity 3.7. If you use an old version you will not be able to use this configuration option.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Gaurav Mehta
    Gaurav Mehta avatar
    43 posts
    Registered:
    09 Dec 2009
    10 Dec 2009
    Link to this post
    Hi there,

    Thanks very much for your reply.

    There are couple of things that i would like to mention additionally.

    We are using Sitefinity 3.6
    I don't have sitefinity installed on my system where I am creating this new class library project.
    Sitefinity is installed on our Dev server and we using admin interface to manage site.
    Now our client has following requirement:

    <Requirements>
    When SiteFinity redirects a user from a HTTPS version of a page to the HTTP version the HTTP status code is 302.  Is it possible to change it to a 301 code.
    For example if a user enters https://www.mysite.com/default.aspx and gets redirected to http://www.mysite.com/default.aspx the status code should be 301, SiteFinity currently gives it a code of 302.

    </Requirements>

    Do u have any solution for this for sitefinity 3.6 ?

    Please let me know asap.

    Regarding your response :

    2. The namespace of ICmsUrlContext  is Telerik.Cms.Web. Try using Telerik.Cms.Web.ICmsUrlContext
    I did try to use it like given below but it did not work
    protected override void ProcessSslRedirect(HttpContext context, Telerik.Cms.Web.ICmsUrlContext url)
    {
    }

    3. SslRedirection is implemented from Sitefinity 3.7. If you use an old version you will not be able to use this configuration option.

    Any solution for Sitefinity 3.6

    Regards,
    Gaurav

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    10 Dec 2009
    Link to this post
    Hi Gaurav Mehta,

    If you are going to use SSL I suggest that you should upgrade your project. The code you have copied is not prepared to work for versions before Sitefinity 3.7. The only way that  you can get similar behavior working with Sitefinity 3.6 is creating new HttpModule and making redirect in BeginRequest, but this is not a solution.


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Gaurav Mehta
    Gaurav Mehta avatar
    43 posts
    Registered:
    09 Dec 2009
    10 Dec 2009
    Link to this post
    Hi Ivan Dimitrov,

    Thanks very much for you reply.

    File version of Telerik.Cms.dll (in bin folder) is : 3.6.1936.2
    We are using Sitefinity :Release Sitefinity 3.6 SP2 -  3.6.1936.2 - standard

    As mentioned earlier our main goal is to achieve following client requirements

    <Requirements>
    When SiteFinity redirects a user from a HTTPS version of a page to the HTTP version the HTTP status code is 302.  Is it possible to change it to a 301 code.
    For example if a user enters https://www.mysite.com/default.aspx and gets redirected to http://www.mysite.com/default.aspx the status code should be 301, SiteFinity currently gives it a code of 302.

    </Requirements>

    If you suggest to upgrade to latest version to achieve this requirement then we are ready for upgrade.
    In this case please let us know how to upgrade to latest version of the product ?

    Please kindly Note that our CMS site is Live now so if there are any additional details that needs to be taken care during the upgrade process then please also mention them.

    Regards,
    Gaurav

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    10 Dec 2009
    Link to this post
    Hi Gaurav Mehta,

    Here is a link to our Upgrade Instructions that you should follow.
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. gabs002
    gabs002 avatar
    64 posts
    Registered:
    17 Dec 2009
    15 Jan 2010
    Link to this post
    Hello!

    I do want to redirect my pages to https. where in my project do I have to change settings? Do I have to implement it in the Global.asax, or Default.aspx or in the web.config?

    On the IIS the settings are fine. The only problem is, that I don't know where the Startsite will be called.

    Thank you,
    Regards, Gabriele
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Jan 2010
    Link to this post
    Hello Gabriele Muerth,

    Each page has a Properties tab form where you can set Require SSL to Yes or No. This will force the page to require ssl when you make a request to it.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. gabs002
    gabs002 avatar
    64 posts
    Registered:
    17 Dec 2009
    18 Jan 2010
    Link to this post
    Hello and thank you for your answer.
    I have already found this setting in the sitefinity cms. But my problem is, that I develop the page on my local computer, where I do not have/need SSL, but I need SSL on the server, where the page should be hosted. Is there a possibility to set this setting only on the server, but not on my local computer, or do I have to make SSL run on my local computer too?

    Thank you,
    Gabriele
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    18 Jan 2010
    Link to this post
    Hi Gabriele Muerth,

    Once you migrate the project on your production you may set the require SSL to each of your pages. It is not necessary to set this property on your local host.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. gabs002
    gabs002 avatar
    64 posts
    Registered:
    17 Dec 2009
    18 Jan 2010
    Link to this post
    Hello!

    How do I have to make this settings? Sitefinity CMS is not running on the server where the website ist hosted.
    I have already tried to change a setting in the web.config:

    <notifications defaultProvider="Notifications">  
                <providers> 
                    <clear/> 
                    <add name="Notifications" type="Telerik.Notifications.Data.DefaultProvider, Telerik.Notifications.Data" connectionStringName="DefaultConnection" EnableSsl="true" MergedFields="FirstName;LastName" SendingInterval="1000"/>  
                </providers> 
            </notifications> 

    ...but it does not work.

    Hope you can help me with my concern.

    Thank you,
    Gabriele
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    18 Jan 2010
    Link to this post
    Hello Gabriele Muerth,

    The web.config settings you have posted is for Newsletters module. It does not have anything to do with cms pages.

    "Each page has a Properties tab form where you can set Require SSL to Yes or No. This will force the page to require ssl when you make a request to it."

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. Ganesh
    Ganesh avatar
    4 posts
    Registered:
    28 Jul 2006
    17 Oct 2011
    Link to this post
    Ivan:
    I am running CMS version 4.1  and our entire site is "https" only. Without having to set at each page level the "Require SSL" property - how would I do it at the entire site level?

    Thanks,
    Ganesh
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    18 Oct 2011
    Link to this post
    Hello Ganesh,

    SSL setup is a property of the PageNode. You can set it programmatically using the API.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  15. Nick Wharf
    Nick Wharf avatar
    1 posts
    Registered:
    17 Feb 2009
    20 Apr 2012
    Link to this post
    It looks like this was never answered on whether or not you can modify Sitefinity to issue a 301 redirect as opposed to a 302. We are running v3.7, cannot upgrade at this time, and need to have http to https redirect as a 301.
Register for webinar
15 posts, 0 answered