[英]Redirect to ReturnUrl after successful cookie authentication in Owin, Katana & Nancy
我正在使用Owin,Katana和Nancy来托管一个带有身份验证所需部分的简单网站。 注意我也在使用nuget包 - Nancy.MSOwinSecurity
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = Constants.AuthenticationType,
LoginPath = new PathString("/Login"),
});
app.UseNancy();
这是我的模块代码
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"];
};
}
}
我的提交表格
<form name="login" action="/login" method="post" accept-charset="utf-8">
<ul>
...
</ul>
</form>
现在我想在成功登录ReturnUrl后重定向 -
例如登录?ReturnUrl =%2Fblah%2blahblah
似乎没有像表单身份验证那样的重定向方法,而且查询字符串参数属性为空。
你试过Response.AsRedirect("/");
或GetRedirect("/");
在NancyContext
使用您的代码示例:
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);
};
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.