Sunday, 15 March 2015

redirect - How do you use Fluent Security to Setup SSL Redirection in an ASP.net MVC application? -



redirect - How do you use Fluent Security to Setup SSL Redirection in an ASP.net MVC application? -

what best way utilize fluent security setup ssl redirection on controllers' views within mvc web app?

the best way create custom policy , policy handler. here how completed it:

my custom policy

public class requiresslpolicy : isecuritypolicy { public policyresult enforce(isecuritycontext context) { var req = httpcontext.current.request; if (!req.issecureconnection && !req.islocal) homecoming policyresult.createfailureresult(this, "a secure connection required."); homecoming policyresult.createsuccessresult(this); } }

my custom policy handler

public class requiresslpolicyviolationhandler : ipolicyviolationhandler { public actionresult handle(policyviolationexception exception) { var req = httpcontext.current.request; var url = req.url.tostring().tolower().replace("http:", "https:"); homecoming new redirectresult(url); } }

code add together policy controller or actions within controller

c.for<accountcontroller>().addpolicy<requiresslpolicy>();

and that'it! of course of study need create sure configuring dependency injection correctly , next fluent security naming conventions. 1 time correct, should see code works perfectly!

asp.net-mvc redirect ssl fluent-security

No comments:

Post a Comment