简体   繁体   English

在Owin,Katana和Nancy成功进行cookie身份验证后,重定向到ReturnUrl

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

I am using Owin, Katana and Nancy to host a simple site with an authentication required section. 我正在使用Owin,Katana和Nancy来托管一个带有身份验证所需部分的简单网站。 Note I am also using nuget package - Nancy.MSOwinSecurity 注意我也在使用nuget包 - 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 submitting form 我的提交表格

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

Now I am looking to redirect after successful login to the ReturnUrl - 现在我想在成功登录ReturnUrl后重定向 -

eg Login?ReturnUrl=%2Fblah%2blahblah 例如登录?ReturnUrl =%2Fblah%2blahblah

There seems to be no redirect method like in forms authentication plus the query string parameters property is empty. 似乎没有像表单身份验证那样的重定向方法,而且查询字符串参数属性为空。

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

Using your code sample: 使用您的代码示例:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM