Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The redirect loop is occurring because the code is only checking if the HTTPS redirect is required, not if the current request is already HTTPS (i.e. the redirect has already happened). </p> <pre><code>if (RequireSecure &amp;&amp; !filterContext.HttpContext.Request.IsSecureConnection){ // redirect to HTTP version of page builder.Scheme = Uri.UriSchemeHttps; builder.Port = 44300; filterContext.Result = new RedirectResult(builder.Uri.ToString()); } else{ // non secure requested if (filterContext.HttpContext.Request.IsSecureConnection){ HandleNonHttpRequest(filterContext); } } </code></pre> <p>Although the <code>RequireHttps</code> should work correctly for this, unless you need to redirect to the port specified.</p> <p>EDIT: Refactored attribute</p> <pre><code>public class HttpsAttribute : System.Web.Mvc.RequireHttpsAttribute { public bool RequireSecure = false; public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext) { var requestUri = HttpContext.Current.Request.Url; var requestIsSecure = HttpContext.Current.Request.IsSecureConnection; if (RequireSecure &amp;&amp; !requestIsSecure) filterContext.Result = Redirect(requestUri, Uri.UriSchemeHttps, 44300); else if (!RequireSecure &amp;&amp; requestIsSecure) filterContext.Result = Redirect(requestUri, Uri.UriSchemeHttp, 80); } private RedirectResult Redirect(Uri uri, string scheme, int port) { return new RedirectResult(new UriBuilder(uri) { Scheme = scheme, Port = port }.Uri.ToString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload