Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

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:

http://localhost:80/account/logon?returnurl=/user

the administrator url is:

http://localhost:80/account/logon?returnurl=/administrator

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 } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -