Redirect to ReturnUrl after successful cookie authentication in Owin, Katana & Nancy

I use Owin, Katana and Nancy to host a simple site with the required separation. Note. I also use the nuget package - Nancy.MSOwinSecurity

app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = Constants.AuthenticationType, LoginPath = new PathString("/Login"), }); app.UseNancy(); 

Here is my module code

 public class LoginModule : NancyModule { public LoginModule() { Post["login"] = p => { var name = Request.Form.name; var auth = Context.GetAuthenticationManager(); var claims = new List<Claim> {new Claim(ClaimTypes.Name, name)}; var id = new ClaimsIdentity(claims, Constants.AuthenticationType); auth.SignIn(id); // redirect how???? return View["index"]; }; } } 

My feed form

 <form name="login" action="/login" method="post" accept-charset="utf-8"> <ul> ... </ul> </form> 

Now I am looking for a redirection after successfully entering ReturnUrl -

eg. To come in? ReturnUrl =% 2Fblah% 2blahblah

It seems that there is no redirect method, for example, when authenticating forms, plus the query string parameter property is empty.

+7
authentication c # owin katana nancy
source share
1 answer

Have you tried Response.AsRedirect("/"); or GetRedirect("/"); on NancyContext

Using the sample code:

 public class LoginModule : NancyModule { public LoginModule() { Post["login"] = p => { var name = Request.Form.name; var auth = Context.GetAuthenticationManager(); var claims = new List<Claim> {new Claim(ClaimTypes.Name, name)}; var id = new ClaimsIdentity(claims, Constants.AuthenticationType); auth.SignIn(id); return Response.AsRedirect(p.Request.Query.RedirectUrl); }; } } 
+4
source share

All Articles