c# - returnUrl always null even when getting the login page -
i see has been asked quite lot solution posting form. i'm not getting value when redirecting custom login page. here's logincontroller
// get: /login [allowanonymous] public actionresult index(string returnurl) { viewbag.returnurl = returnurl; return view(); }
web.config
<authentication mode="forms"> <forms loginurl="~/login" timeout="2880" cookieless="usecookies"/> </authentication>
and custom userauthorize filter
public override void onauthorization(authorizationcontext filtercontext) { // if authorized, handle accordingly if (this.authorizecore(filtercontext.httpcontext)) { base.onauthorization(filtercontext); } else { // otherwise redirect specific authorized area filtercontext.result = new redirectresult("~/login"); } }
thanks
if using custom authorizing method, must addreturnurl
parameter manually. normally, formsauthentication
class handles adding parameter querystring.
var request = filtercontext.httpcontext.request; // return url if exist if (request.httpmethod.equals("get", system.stringcomparison.currentcultureignorecase)) returnurl = request.rawurl; filtercontext.result = new redirecttorouteresult(new routevaluedictionary( new { controller = "login", action = "index", returnurl = returnurl, }));
Comments
Post a Comment