Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:53:20+00:00 2026-06-15T23:53:20+00:00

I have a custom RequireHttps Action Filter. I log in and my site is

  • 0

I have a custom RequireHttps Action Filter. I log in and my site is https, but when you type in a http page while logged in, the action filter never gets hit. I know this because I have logging on and I dont see it being logged anymore. The reason I want it to get it is to test if the user is authenticated and do a 301 redirect to the same page in SSL, but it is never being hit.

Global.asax

 kernel.BindFilter<UseHttpsFilter>(FilterScope.Action, 0)
                          .WhenActionMethodHas<UseHttpsAttribute>()
                          .WithConstructorArgumentFromActionAttribute<UseHttpsAttribute>("requireSecure", q => q.RequireSecure);

                    kernel.BindFilter<UseHttpsFilter>(FilterScope.Controller, 0)
                          .WhenActionMethodHas<UseHttpsAttribute>()
                          .WithConstructorArgumentFromControllerAttribute<UseHttpsAttribute>("requireSecure", q => q.RequireSecure);

UseHttpsAttribute.cs

namespace Site.Web.Attributes
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class UseHttpsAttribute : FilterAttribute
    {
        public bool RequireSecure { get; set; }

        public UseHttpsAttribute(bool requireSecure)
        {
            RequireSecure = requireSecure;
        }
    }

    public class UseHttpsFilter : ActionFilterAttribute
    {
        protected static readonly NLogLogger Logger = new NLogLogger();

        public bool RequireSecure = false;

        public UseHttpsFilter(bool requireSecure)
        {
            Logger.Debug("Use Https Constructor: " + requireSecure);
            RequireSecure = requireSecure;
        }

        protected virtual void HandleNonHttpRequest(ActionExecutingContext filterContext)
        {
            if (string.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                string url = "http://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
                filterContext.Result = new RedirectResult(url, true);
            }
        }

        protected void HandleNonHttpsRequest(ActionExecutingContext filterContext)
        {
            if (string.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                string url = "https://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
                filterContext.Result = new RedirectResult(url, true);
            }
        }


        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Logger.Debug("Use Https Authenticated: " + filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated);

            if (filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated || HttpContext.Current.Session[Config.ViewData.MemberSession] != null)
            {
                RequireSecure = true;
            }

            Logger.Debug("Use Https Local: " + filterContext.RequestContext.HttpContext.Request.IsLocal);

            if (filterContext.RequestContext.HttpContext.Request.IsLocal)
                RequireSecure = false;

            if (RequireSecure)
            {
                Logger.Debug("Use Https Secure Connection: " + filterContext.HttpContext.Request.IsSecureConnection);

                if (!filterContext.HttpContext.Request.IsSecureConnection)
                {
                    HandleNonHttpsRequest(filterContext);
                }
            }
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:53:21+00:00Added an answer on June 15, 2026 at 11:53 pm

    Found out it was because I had this for the first binding

    .WhenActionMethodHas<UseHttpsAttribute>()
    

    intead of

    .WhenControllerHas<UseHttpsAttribute>()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom PHP site and using this script for pagination. echo Page <strong>$pagenum</strong>
I have custom slider sitting at the top of my page but I'm having
I have custom page and id of list item. How can i show sharepoint
I have custom list_row : <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=match_parent android:orientation=horizontal android:layout_width=match_parent android:layout_height=wrap_content android:baselineAligned=false> <Button
I have custom javascript code for tabs which works fine, but Im trying to
I have custom radio buttons which I've borrowed from this website: http://www.inserthtml.com/2012/06/custom-form-radio-checkbox/ Unfortunately, I'm
I have custom content type, which has target association. I want to set up
I have custom type name Netsgroup which is a collection of Net class. Net
I have custom AJAX code on a blog page that I set up to
I have custom classes in Company.System namespace. But now I am writing code referencing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.