I'm developping a webapplication. For the security of the users information i need a https connection. I'm developping this local at the moment. I have followed the tutorial on: http://weblogs.asp.net/dwahlin/archive/2009/08/25/requiring-ssl-for-asp-net-mvc-controllers.aspx
When I build my project the page loads but the url is: http://...
In my code i have placed:
[RequiresSSL]
public ActionResult Index()
{
//var model = Adapter.EuserRepository.GetAll();
return View(db.Eusers.ToList());
}
code from site:
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);
}
}
}
What am i missing that the url isn't https based? Is this because I'm working local?
Thanks in advance
Your filter checks to see if the request is local with this statement: && !req.IsLocal
. If it is, then it doesn't redirect. If you remove that statement then you'll be required to access the action via HTTPS regardless if you're local or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With