asp.net - Use setting in session to set SSL enforcement -


i have below code in global.ascx. works fine when debugging, on live site causes issues related session, appears session not available/created @ points, blows up. setting stored in session (appsettings.issslenforced retreived session), have read there, right thinking of perhaps putting in master page, feel leave requests vulnerable. there better alternative?

protected void application_beginrequest(object sender, eventargs e) {       try       {            if (!request.issecureconnection && appsettings.issslenforced)            {                response.redirect(request.url.tostring().replace("http:", "https:"));            }       }       catch (exception ex)       {            logmanager.inserterrorlog(ex);       } } 

try using application_prerequesthandlerexecute rather application_beginrequest:

protected void application_prerequesthandlerexecute(object sender, eventargs e) {       try       {            if (!request.issecureconnection && appsettings.issslenforced)            {                response.redirect(request.url.tostring().replace("http:", "https:"));            }       }       catch (exception ex)       {            logmanager.inserterrorlog(ex);       } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -