Also habe ich das [RequiresHttps] Attribut gefunden, aber einmal in https stecken Sie irgendwie fest, also habe ich versucht, Aktionen auf einer einzigen URL (und Schema) durchführen zu können, habe ich festgestellt, dass ich meinen eigenen ExtendedController erstellen musste, um für Aktionen, die nicht [RequireHttps] verwenden, wieder auf http zurückzukehren.
Ich frage mich nur, ob das, was ich mache, in Ordnung ist oder ob es einen besseren Weg gibt?
public class ExtendedController : Controller
{
protected virtual void HandleHttpRequest(AuthorizationContext filterContext)
{
if (!string.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException("Kann nicht zwischen https und http posten.");
}
string url = "http://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
filterContext.Result = new RedirectResult(url);
}
protected override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
object[] attributes = filterContext.ActionDescriptor.GetCustomAttributes(true);
if (!attributes.Any(a => a is RequireHttpsAttribute))
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
if (filterContext.HttpContext.Request.IsSecureConnection)
{
this.HandleHttpRequest(filterContext);
}
}
}
}