重定向Owin,卡塔纳和放大器成功cookie认证后RETURNURL;南希 [英] Redirect to ReturnUrl after successful cookie authentication in Owin, Katana & Nancy
问题描述
我使用Owin,武士刀和南希举办一个简单的网站,一个需要身份验证部分。
请注意我也使用的NuGet包 - Nancy.MSOwinSecurity
I am using Owin, Katana and Nancy to host a simple site with an authentication required section. Note I am also using nuget package - Nancy.MSOwinSecurity
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = Constants.AuthenticationType,
LoginPath = new PathString("/Login"),
});
app.UseNancy();
下面是我的模块code
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"];
};
}
}
我的提交表单
<form name="login" action="/login" method="post" accept-charset="utf-8">
<ul>
...
</ul>
</form>
现在我期待成功登录到RETURNURL后重定向 -
Now I am looking to redirect after successful login to the ReturnUrl -
例如。登录?RETURNURL =%2Fblah%2blahblah
e.g. Login?ReturnUrl=%2Fblah%2blahblah
有看起来像表单认证没有重定向方法加上查询字符串参数属性为空。
There seems to be no redirect method like in forms authentication plus the query string parameters property is empty.
推荐答案
你试过 Response.AsRedirect(/);
或 GetRedirect (/);
在 NancyContext
使用您的code样品:</ P>
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);
};
}
}
这篇关于重定向Owin,卡塔纳和放大器成功cookie认证后RETURNURL;南希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!