I know there are many posts regarding and it works fine if the action method which i am calling is just a get method, but it fails if the action method has a 'Post' attribute because in the code we do a redirect to the url and not a post
I am using code below...
using System;
using System.Web;
using System.Web.Mvc;
namespace Helpers
{
public class RequiresSSL : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestBase req = filterContext.HttpContext.Request;
HttpResponseBase res = filterContext.HttpContext.Response;
//Check if we're secure or not and if we're on the local box
if (!req.IsSecureConnection && !req.IsLocal)
{
var builder = new UriBuilder(req.Url)
{
Scheme = Uri.UriSchemeHttps,
Port = 443
};
res.Redirect(builder.Uri.ToString());
}
base.OnActionExecuting(filterContext);
}
}
}