Ned*_*son 7 c# authentication nancy owin katana
我正在使用Owin,Katana和Nancy来托管一个带有身份验证所需部分的简单网站.注意我也在使用nuget包 - Nancy.MSOwinSecurity
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = Constants.AuthenticationType,
LoginPath = new PathString("/Login"),
});
app.UseNancy();
Run Code Online (Sandbox Code Playgroud)
这是我的模块代码
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"];
};
}
}
Run Code Online (Sandbox Code Playgroud)
我的提交表格
<form name="login" action="/login" method="post" accept-charset="utf-8">
<ul>
...
</ul>
</form>
Run Code Online (Sandbox Code Playgroud)
现在我想在成功登录ReturnUrl后重定向 -
例如登录?ReturnUrl =%2Fblah%2blahblah
似乎没有像表单身份验证那样的重定向方法,而且查询字符串参数属性为空.
小智 4
你有没有尝试过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);
};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7371 次 |
| 最近记录: |