Tôi đang phát triển một ứng dụng web. Để bảo mật thông tin người dùng, tôi cần kết nối https. Tôi đang phát triển địa phương này vào lúc này. Tôi đã theo các hướng dẫn về: http://weblogs.asp.net/dwahlin/archive/2009/08/25/requiring-ssl-for-asp-net-mvc-controllers.aspxCách sử dụng https trong C#?
Khi tôi xây dựng dự án của tôi tải trang nhưng url là: http: // ...
Trong mã của tôi đã đặt:
[RequiresSSL]
public ActionResult Index()
{
//var model = Adapter.EuserRepository.GetAll();
return View(db.Eusers.ToList());
}
mã từ trang web:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace extranet.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);
}
}
}
Tôi thiếu url nào không dựa trên https? Đây có phải là vì tôi đang làm việc tại địa phương không?
Cảm ơn trước
wow ... làm thế nào tôi không thể thấy rằng * xấu hổ *, khi tôi xóa đoạn mã đó sau đó tôi nhận được 401 - không thể kết nối với máy chủ cục bộ, nhưng liên kết là https ngay bây giờ ... – thomvlau
Bạn đã cài đặt chứng chỉ (kiểm tra) chưa? –