开发者

Filter breaks when adding it globally

开发者 https://www.devze.com 2023-03-17 18:38 出处:网络
I\'m using Luke Sampson\'s filter in asp.net MVC3 called [ExitHttpsIfNotRequired], which can be applied to a controller or action and automatically redirects to HTTP if [RequireHttps] isn’t also app开

I'm using Luke Sampson's filter in asp.net MVC3 called [ExitHttpsIfNotRequired], which can be applied to a controller or action and automatically redirects to HTTP if [RequireHttps] isn’t also app开发者_如何学编程lied.

This works perfectly when I apply it to a single controller. However, as I will be applying this to 99% of my controllers I decided to add it to my global filters:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    GlobalFilters.Filters.Add(new ExitHttpsIfNotRequiredAttribute());

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
}

It now continues to work for http:// pages, but as soon as I visit anything on https:// I get an error 500. I have tried debugging countless times but I can't seem to replicate the issue locally - does anyone have any ideas?

Thank you in advance.


Solved! My main ssl controller was calling another non-ssl controller (using Html.Action) in the layout - an eventuality for which the filter is not set up for:

I fixed this by adding the following to Luke's [ExitHttpsIfNotRequired] filter:

// Abort if it's a child controller
if (filterContext.IsChildAction) return;
0

精彩评论

暂无评论...
验证码 换一张
取 消