I use ActionFilter (see below) to determine if there is 1. the current controller / action requires SSL and 2. SSL is currently being used and redirected accordingly.
This works fine locally (using a dummy certificate in IIS 7), but as soon as I get it on the server, I get an error message indicating an infinite redirection loop.
Any ideas?
public class SslFilter : ActionFilterAttribute { public SslFilter(bool sslRequired) { SslRequired = sslRequired; } public bool SslRequired { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase req = filterContext.HttpContext.Request; HttpResponseBase res = filterContext.HttpContext.Response; var builder = new UriBuilder(req.Url); if (SslRequired && !req.IsSecureConnection) { builder.Scheme = Uri.UriSchemeHttps; builder.Port = 443; res.Redirect(builder.Uri.ToString()); } else if (!SslRequired && req.IsSecureConnection) { builder.Scheme = Uri.UriSchemeHttp; builder.Port = 80; res.Redirect(builder.Uri.ToString()); } base.OnActionExecuting(filterContext); } }
Firefox Error:
Page not redirecting correctly
Firefox has detected that the server redirects the request for this address in a way that will never be complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
user280025
source share