我正在编写一个示例应用。利用OWIN和UseCookieAuthentication
。后者接受CookieAuthenticationOptions
,其LogoutPath
属性。此属性具有以下相关注释:
如果为LogoutPath提供了中间件,那么对该路径的请求将根据ReturnUrlParameter重定向。
然而,我无法弄清楚这是否有用,或者它只是代表了一些隐含的契约,你的代码会做些什么。例如,如果我利用AuthenticationManager.SignOut()
,我会期望调用注销路径端点。
答案 0 :(得分:2)
感谢Khalid Abuhakmeh提供更多见解。但是,我的混淆最终是假设在指定 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#account").change(function() {
var dataString1 = "q="+$("#account").val();
$.ajax
({
url: "displayfacilities.php",
type : "POST",
cache : false,
data : dataString1,
success: function(result1)
{
alert("Response from PHP file 1");
var dataString2 = "f=" + $("#account").val();
$.ajax
({
url: "updatefacilities.php",
type : "POST",
cache : false,
data : dataString2,
success: function(result2)
{
alert("Response from PHP file 2");
}
}
});
});
});
});
</script>
属性时映射了隐式端点。添加以下内容后,请求LogoutPath
按预期工作:
/logout?ReturnUrl=/
如果没有明确的地图,我会得到404。
作为另外的附注,我也错误地认为向app.Map("/logout", logout =>
{
logout.Run(context =>
{
context.Authentication.SignOut();
return Task.FromResult(0);
});
});
提供AuthenticationProperties
- 实例将允许我指定return-url(而不是将其作为请求url的一部分) 。它似乎只适用于external cookie authentication。
答案 1 :(得分:1)
查看Microsoft.Owin.Security
的反编译代码,如果指定了 LogOutPath ,则会尝试执行重定向。它将重定向到查询字符串中的 returnUrl 参数。所以再次总结一下。
如果当前请求与LogOutPath匹配并且它具有returnUrl参数,则OWIN中间件将自动重定向到查询字符串中指定的returnUrl。否则它什么都不做。
有用的功能可能是,您注销并希望重定向回到现在已降低匿名用户功能的同一页面。
bool shouldLoginRedirect = num1 != 0;
int num2;
if (shouldSignout)
{
PathString logoutPath = this.get_Options().LogoutPath;
// ISSUE: explicit reference operation
if (((PathString) @logoutPath).get_HasValue())
{
num2 = PathString.op_Equality(((AuthenticationHandler) this).get_Request().get_Path(), this.get_Options().LogoutPath) ? 1 : 0;
goto label_22;
}
}
num2 = 0;
label_22:
bool shouldLogoutRedirect = num2 != 0;
if ((shouldLoginRedirect || shouldLogoutRedirect) && ((AuthenticationHandler) this).get_Response().get_StatusCode() == 200)
{
string str = ((AuthenticationHandler) this).get_Request().get_Query().Get(this.get_Options().ReturnUrlParameter);
if (!string.IsNullOrWhiteSpace(str) && CookieAuthenticationHandler.IsHostRelative(str))
this.get_Options().Provider.ApplyRedirect(new CookieApplyRedirectContext(((AuthenticationHandler) this).get_Context(), this.get_Options(), str));
}
}