Featured post
asp.net mvc - IF statement not being executed C# MVC -
i have mvc application, has 2 areas - administrator, , user. wanted do, on first login, user activate account, agree terms , conditions, etc. application uses asp membership api.
i have inserted if statement post login action in account controller, after debugging, appears if statement never executed. if take @ i'd grateful. have feeling small i'm missing.
the login url user is:
the administrator url is:
however both use same login action in account controller hence need use if statement differentiate between two.
here code post logon action. string returnurl "/user" not "user" discovered after debugging through code.
[httppost] public actionresult logon(logonmodel model, string returnurl) { if (modelstate.isvalid) { if (membershipservice.validateuser(model.username, model.password)) { formsservice.signin(model.username, model.rememberme); if (!string.isnullorempty(returnurl)) { return redirect(returnurl); } else { string url = returnurl; if (url == "/user") { modelcontainer ctn = new modelcontainer(); myapp.data.user p = ctn.users.first(t => t.userid == userservices.currentuserid); string status = p.accountstatus; if (status != "active") { return redirecttoaction("contract", "home"); } else { return redirecttoaction("index", "home"); } } else return redirecttoaction("index", "home"); } } else { modelstate.addmodelerror("", "the user name or password provided incorrect."); } } // if got far, failed, redisplay form return view(model); }
it seems skip after else here:
if (!string.isnullorempty(returnurl)) { return redirect(returnurl); } else { string url = returnurl;
and jumps right down final redirecttoaction.
i'd grateful if spot anything. if more info needed shout!
this not go further if case when returnurl == "/user"
or other value
if (!string.isnullorempty(returnurl)) { return redirect(returnurl); }
if not null or empty
, , if returnurl == "/user"
, true since "/user"
not null , not empty.
and second part null or empty:
string url = returnurl; if (url == "/user") {
so "appear" isn't working.
my suggestion return "true" case first in if/ else clarity:
if (string.isnullorempty(returnurl)) { // default cases } else { // redirect returnurl }
- Get link
- X
- Other Apps
Comments
Post a Comment