i working on asp.net core, mvc 6 application. have appcontroler initial controller , if user tries go action has [authorize] attribute, redirect authcontroller login, passing in returnurl return. once authenticated, use ... return redirecttoaction(returnurl).
in debug, can see returnurl string set /app/timesheets. however, in browser address bar, has address of http://localhost:49940/auth/%2fapp%2ftimesheets. reason appending controller name (auth) in front of returnurl.
here login action in authcontroller
[httppost] public async task<actionresult> login(loginviewmodel vm, string returnurl) { if (modelstate.isvalid) { var signinresult = await _signinmanager.passwordsigninasync(vm.username, vm.password, true, false); if (signinresult.succeeded) { if (string.isnullorwhitespace(returnurl)) { return redirecttoaction("timesheets", "app"); } else { return redirecttoaction(returnurl); } } else { modelstate.addmodelerror("", "username or password incorrect"); } } return view(); }
i can manually enter http://localhost:49940/app/timesheets in browser address bar , correct view. also, if add
returnurl = string.empty; //test only
before line...
if (string.isnullorwhitespace(returnurl))
to cause execute line...
return redirecttoaction("timesheets", "app");
the redirection works fine. has passing in string variable in "/controller/action" format problem.
any ideas?
when have full url already, should return redirect
. doing redirecttoaction
try redirect action under current controller (auth).
if (signinresult.succeeded) { if (string.isnullorwhitespace(returnurl)) { return redirecttoaction("timesheets", "app"); } else { return redirect(returnurl); } }
Comments
Post a Comment