如何使会话无效?
摄制:
反正有没有使之前复制的cookie无效?
我正在使用标准的MVC5注销功能.
public ActionResult LogOff()
{
AuthenticationManager.SignOut();
return RedirectToAction("Index", "Home");
}
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
Run Code Online (Sandbox Code Playgroud)
还尝试只签出cookie.
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Run Code Online (Sandbox Code Playgroud)
想改变SecurityStamp也会有效,但由于索赔没有改变,邮票也没有.
UserManager.UpdateSecurityStampAsync(user.UserName);
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个函数,文档说这应该使会话无效. http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon(v=vs.110).aspx
Session.Abandon();
Run Code Online (Sandbox Code Playgroud) 我正在使用cookie身份验证MVC5
.我的网页每隔1-5秒就严重依赖经过身份验证和未经身份验证的Ajax调用来保持数据更新.因此,我的用户永远不会退出该网站.
我的理想情况:如果用户正在我的网站上主动浏览或执行操作,请保持会话处于活动状态.如果他们在10分钟后打开了一个页面,我希望他们的会话超时,我将使用失败的Ajax调用重定向到登录页面.我认为最好在控制器或动作级别完成.
我尝试按照下面的建议控制会话状态行为,但会话仍然没有超时.在每秒点击ReadOnly/Public一次65秒后,我调用ReadOnly/Authorized并成功从中检索数据.
这是我的CookieAuthentication配置.
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromMinutes(1),
});
}
Run Code Online (Sandbox Code Playgroud)
我的测试页面:
<div id="public"></div>
<div id="authorized"></div>
@section scripts{
<script>
function poll(times) {
var url = '/ReadOnly/Public';
$.ajax({
url: url,
dataType: 'json',
data: null,
cache: false,
success: function (data) {
$('#public').html(times + ' ' + data.test);
},
error: function (data) …
Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于将Dictionary绑定到WPF ListView和ListBox的帖子,但我无法获得在WinRT中工作的等效代码.
<Grid Margin="10" Width="1000" VerticalAlignment="Stretch">
<ListBox Name="StatListView" ItemsSource="{Binding FooDictionary}" >
<ListBox.ItemTemplate>
<DataTemplate >
<Grid Margin="6">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Key}" Margin="5" />
<TextBlock Text="{Binding Value}" Margin="5" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
public Dictionary<string, string> FooDictionary
{
get
{
Dictionary<string, string> temp = new Dictionary<string, string>();
temp.Add("key1", "value1");
temp.Add("key2", "value2");
temp.Add("key3", "value3");
temp.Add("key4", "value4");
return temp;
}
}
Run Code Online (Sandbox Code Playgroud)
什么是正确的绑定?
默认情况下,我的站点启用了 x-frame-options: SAMEORIGIN 标头。我想将它从特定视图中删除,以便仅将该视图托管在 3rd 方 iFrame 中。
public ActionResult Callback1()
{
// Remove the anti-clickjacking setting
Response.Headers.Remove("X-Frame-Options");
Return View();
}
// Does not remove the header
public ActionResult Callback2()
{
// Try to override the setting
Response.Headers["X-Frame-Options"] = "ALLOW-FROM https://foo.com"
Return View();
}
// Results in x-frame-options: ALLOW-FROM https://foo.com, SAMEORIGIN
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。