Khi bạn đặt [RequireHttps]
trên một hành động và người sử dụng công tắc từ HTTP thành HTTPS, tất cả các liên kết tiếp theo sẽ ở lại HTTPS ...ASP.NET MVC [RequireHttps] - trở về http
Có cách nào để chuyển về HTTP?
Khi bạn đặt [RequireHttps]
trên một hành động và người sử dụng công tắc từ HTTP thành HTTPS, tất cả các liên kết tiếp theo sẽ ở lại HTTPS ...ASP.NET MVC [RequireHttps] - trở về http
Có cách nào để chuyển về HTTP?
Về mặt kỹ thuật, bạn có thể làm điều đó
Bạn có thể look at the source của RequireHttpsAttribute
và đảo ngược.
Trong thực tế, có lẽ bạn không nên
Nếu phiên giao dịch vẫn còn sống, it is generally inadvisable to return to HTTP. Đây có thể là số foundation for a variety of attacks, ví dụ: session hijacking.
Cảm ơn tất cả các liên kết - Tôi thường đồng ý với bạn, nhưng tôi có trang "liên hệ với chúng tôi" mà tôi muốn thực thi SSL - phần còn lại của trang web là thông tin. – zam6ak
@ zam6ak Không sao cả. Bạn sẽ được OK nếu phần còn lại của trang web chỉ là thông tin, nhưng bạn hy vọng sẽ đạt được gì khi trở lại HTTP? –
Tôi đọc ở đâu đó mà chuyển đổi các chương trình "đau" SEO. Thật không may, tôi không có liên kết bài viết nữa, và tôi không chắc chắn 100% nếu điều đó đúng ... – zam6ak
có một mô tả khá chi tiết về làm thế nào để xử lý chuyển đổi từ HTTPS trở lại HTTP cho các phương pháp hành động cụ thể tại liên kết này
http://blog.clicktricity.com/2010/03/switching-to-https-and-back-to-http-in-asp-net-mvc/
Dưới đây là thuộc tính 'ExitHttpsIfNotRequired' Tôi sử dụng:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class RetainHttpsAttribute : Attribute
{
}
public class ExitHttpsIfNotRequiredAttribute : FilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// Abort if it's not a secure connection
if (!filterContext.HttpContext.Request.IsSecureConnection) return;
if (filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == "sdsd") return;
// Abort if it's a child controller
if (filterContext.IsChildAction) return;
// Abort if a [RequireHttps] attribute is applied to controller or action
if (filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute), true).Length > 0) return;
if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute), true).Length > 0) return;
// Abort if a [RetainHttps] attribute is applied to controller or action
if (filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(RetainHttpsAttribute), true).Length > 0) return;
if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(RetainHttpsAttribute), true).Length > 0) return;
// Abort if it's not a GET request - we don't want to be redirecting on a form post
if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) return;
// Abort if the error controller is being called - we may wish to display the error within a https page
if (filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == "Error") return;
// No problems - redirect to HTTP
string url = "http://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
filterContext.Result = new RedirectResult(url);
}
}
Điều này có thể được thực hiện với các bộ lọc. Hãy thử tìm kiếm SO, có rất nhiều câu hỏi gần như chính xác giống như của bạn. –