![](/img/trans.png)
[英]How to integrate Android App to Identity Server with ASP.NET Core 3.1 for Authentication?
[英]How to handle session time out using azure identity authentication - .net core app 3.1
如何在闲置 5 分钟左右后退出用户表单 ASP.NET Core MVC 3.1.27 应用程序。 我使用 Azure 身份平台 (Azure AD) 作为身份验证类型创建了应用程序。
我尝试使用微软文档之一来实现它,但它对我不起作用。 请找到文档链接。 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-6.0
我在startup.cs的Configure方法中添加了session中间件class
我在 startup.cs class 的 ConfigureServices 方法中添加了 session 依赖注入服务
在此先感谢您的帮助。
• 您必须在 ASP.Net 应用程序中使用“authenticationElement”来识别查看您的应用程序的用户,方法是使用应用程序架构中的“configuration Element”、“system.web Element”或“authentication Element”以及需要在应用程序的“web.config”文件中编辑的属性和子元素,例如“模式、forms、护照”,如下所示: -
<authentication mode="Windows">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
defaultUrl="default.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
cookieless="UseDeviceProfile" domain=""
enableCrossAppRedirects="false">
<credentials passwordFormat="SHA1" />
</forms>
<passport redirectUrl="internal" />
</authentication>
• 一旦实施了上述身份验证元素架构,这将确保用户在指定的非活动时间段后退出。 此外,除了上述之外,您还可以通过调用“AddIdentity”或“AddDefaultIdentity”参数调用“ConfigureApplicationCookie”class 来配置“Program.cs”中的“app's cookie”,如下所示: -
builder.Services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "/Identity/Account/AccessDenied";
options.Cookie.Name = "YourAppCookieName";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.LoginPath = "/Identity/Account/Login";
// ReturnUrlParameter requires
//using Microsoft.AspNetCore.Authentication.Cookies;
options.ReturnUrlParameter =
CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
其中“ExpireTimeSpan”是cookie过期的持续时间, “SlidingExpiration”将告诉父处理程序,即应用程序模式中的“ConfigureApplicationCookie”和“authentication Element”发布具有配置的过期时间的新cookie。 因此,通过实现上述内容,您可以在 ASP.Net 应用程序中配置不活动超时。
有关更多信息,请参阅以下链接进行澄清:-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.