session - MVC 4 code file (.cs) redirect to an action -


i have created .cs file checking session values.
using session below

 httpcontext.current.session["usrprof"] 

it written in simple .cs file.
can use if in controller can use in normal .cs file
can use redirect action if don't in session

if (httpcontext.current.session["usrprof"] == null) //redirect action. 

you can use redirect response object

if (httpcontext.current.session["usrprof"] == null) {     httpcontext.response.redirect("/controller/action"); } 

hope helps


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -