如何在c#中使用https?
发布时间:2020-12-15 05:39:11 所属栏目:百科 来源:网络整理
导读:我正在开发一个Web应用程序.为了用户信息的安全,我需要一个https连接.我现在正在开发这个地方.我按照教程: http://weblogs.asp.net/dwahlin/archive/2009/08/25/requiring-ssl-for-asp-net-mvc-controllers.aspx 当我构建我的项目页面加载但网址是:http:/
我正在开发一个Web应用程序.为了用户信息的安全,我需要一个https连接.我现在正在开发这个地方.我按照教程:
http://weblogs.asp.net/dwahlin/archive/2009/08/25/requiring-ssl-for-asp-net-mvc-controllers.aspx
当我构建我的项目页面加载但网址是:http:// … 在我的代码我已经放置: [RequiresSSL] public ActionResult Index() { //var model = Adapter.EuserRepository.GetAll(); return View(db.Eusers.ToList()); } 网站代码: 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); } } } 我错过了什么网址不是基于https的?这是因为我在当地工作吗? 提前致谢 解决方法
您的过滤器会检查该请求是否是本地声明:&& !req.IsLocal.如果是,那么它不会重定向.如果删除该语句,则无论您是否在本地,都需要通过HTTPS访问该操作.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |