开发者

Is it possible to turn off ssl at the controller level of an ASP.Net MVC application?

Is there a way maybe via an action filter to turn off 开发者_StackOverflow中文版ssl for specific methods?

Example...if someone somehow hits my Index method and has ssl on...can I redirect to the method again and turn it off?


Global.asax.cs

protected void Application_BeginRequest(){
    if (Context.Request.IsSecureConnection)
        Response.Redirect(Context.Request.Url.ToString().Replace("https:", "http:"));
}

You could add the same code to an action filter:

public class SSLFilter : ActionFilterAttribute {

    public override void OnActionExecuting(ActionExecutingContext filterContext){
        if (filterContext.HttpContext.Request.IsSecureConnection){
            var url = filterContext.HttpContext.Request.Url.ToString().Replace("https:", "http:");
            filterContext.Result = new RedirectResult(url);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜