- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一个应用程序池回收对我的网络应用程序的用户完全透明。
目前,在 IIS 7 应用程序池回收后,所有登录到我的 Web 应用程序的用户都将被踢出并需要重新登录(Context.User.Identity.IsAuthenticated 设置为 false)。我使用 SQL 状态服务器,我使用表单例份验证,并且两者都配置为使用 cookie。我的印象是 .NET 和/或 IIS 处理 cookie 的身份验证。
但是,每次应用程序池被回收时 Context.User.Identity.IsAuthenticated 设置为 false (我不知道这发生在哪里)我的用户被踢出并需要重新登录。我可以看到 session id 在整个登录过程中保持不变,我还可以在数据库/状态服务器中查看此 session 信息。
我不知道这是 session 问题还是 cookie 问题。
请帮忙!
登录方式:
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
{
if (!ValidateLogOn(userName, password))
{
return View();
}
FormsAuth.SignIn(userName, true); // uses FormsAuthentication.SetAuthCookie(username, true);
Session["userName"] = userName;
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
public class CookieAuthorizeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext lvContext = HttpContext.Current;
if (!lvContext.User.Identity.IsAuthenticated)
{
lvContext.Response.Redirect("~/Account/Logon");
}
else
{
FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthentication.RenewTicketIfOld(identity.Ticket);
}
base.OnActionExecuting(filterContext);
}
}
<authentication mode="Forms">
<forms cookieless="UseCookies" loginUrl="~/Account/LogOn" slidingExpiration="true" name=".ASPXAUTH" requireSSL="false" timeout="2880" />
</authentication>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<remove name="UrlRoutingModule" />
<remove name="Session" />
<remove name="FormsAuthentication" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="NHibernateMvcSessionModule" type="EpnNHibernateBase.NHibernateMvcSessionModule, EpnNHibernateBase" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</modules>
最佳答案
我能够自己找到解决方案。问题不在于如何以编程方式处理身份验证或我如何对用户进行身份验证。问题在于我如何在 IIS/web.config 中配置身份验证。
我仔细按照下面列出的链接中的步骤进行操作:
Configuring Forms Authentication (IIS 7) (在每个相关部分上进行分支)
Configuring Machine Keys in IIS 7 <-- 特别是这个
在密切遵循这些步骤之后,我能够正确生成机器 key 。
native key 如下(带假 key ):
<machineKey decryptionKey="ASDF3WS545AS5D4F8254A12DAFA5SDF7,IsolateApps" validation="3DES" validationKey="A65A6S5DF46ASD4F89WEF6SAD2F4A68EF4AW65F4D3A2F4AS6DF89A98D4F6A5SD4F6A5SDF46ASD8F4A6S5DF46AS5D4F6AS5DF49AS8DF46AS5D4F6AS5DF46SAD5F,IsolateApps" />
httpModules
和
system.webServer:modules
web.config
中的部分需要添加以下模块:
<remove name="Session" />
<remove name="FormsAuthentication" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
关于asp.net - MVC - 用户必须在 IIS Recycle 上重新进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3960496/
在标题为“Managing Bitmap Memory”的文档中,您可以找到以下声明: Caution: You should use recycle() only when you are sure
另一个Recycler View里面有一个Recycler View,都需要垂直滚动。外部 Recycler View 可以正确滚动,但内部 Recycler View 不能。 代码如下: Linea
几天前,我们在 Play 商店发布了一个应用程序,它处理高质量的位图并且完全是关于编辑它们。 当我们意识到 20% 的设备出现内存不足错误时,一切进展顺利。所以我们检查了我们的代码,发现 Androi
我有两个 Activity :MainActivity 和 Activity2。 MainActivity 只需通过 Intent 打开第二个。 要从 Activity2 返回到 MainActivi
我想在 Jetpack compose 中创建以下布局。 我尝试在垂直可滚动框中创建两个列表,但这是不可能的,因为我得到了这个错误: “java.lang.IllegalStateException:
我在 xml 中使用以下代码生成两个 RadioButtons,它们之间有分隔线: 这工作正常,并且在 ViewPager
我使用以下 xml 可绘制对象作为我的 recyclerview 列表项的背景。 touch_selector.xml touch_selector_base.xml
我进行了很多搜索,我所做的是创建一个项目列表,其中包含简单的数字并具有选中和未选中的复选框,因此当我快速点击列表时,它会崩溃并生成 ArrayIndexOutOfBound Exception 所以我
我正在尝试添加一些点击动画 as shown here在我的回收者看来,但没有成功。这是我的一些代码。 在我的 Activity 中 @Override protected void onCreate
我在回收站 View 中有一个歌曲列表。我需要更改之前播放的行的背景颜色。 所以在我的onBindViewHolder我有这个。 if(activeAudioIndex
对于房间分贝的目的。我想在 Recycler View 中运行一些协程。 必要的挂起函数作为类参数处理: class RecyclerAdapter (private val exist : su
我想创建一个列表,例如 To-Do List。 在此用户可以选择/取消选择一个项目,根据他们的优先级重新排序。在当前情况下,我可以使用 为他们提供上述所有功能。 ItemTouchHelper.Sim
我必须与 IBinder 合作s 和 Parcel s。我已经浏览了所有 IBinder , Binder , 和 Parcel文档,找不到任何关于何时调用 Parcel.recycle 的内容(我也
我正在尝试将回收站 View 滚动到底部,但问题是我的行项目高度是否大于滚动停止在项目顶部的屏幕高度。是否可以手动滚动到回收站 View 的最底部? recyclerView.scrollToPosi
我的 Activity 有一个谷歌的 ViewModel 来获取一些模型项目。然后将这些项目转换为 RecyclerView 的适配器项目。一个 RecyclerView 还支持多种类型的适配器项。
我目前正在开发一个 Azure 项目,该项目可在本地使用模拟器资源 100% 运行。我现在正在尝试部署辅助角色,但遇到了一个问题,我不确定如何解决。 在我的 Azure 门户中部署辅助角色后,这两个实
我正在为我的回收站 View 项目使用约束布局。为了动画(展开/折叠)它们,我使用约束集动画。开场动画在所有项目上运行良好。关闭动画也运行良好,但是当关闭动画在不是最后一个的项目上开始时,所有项目在动
我一直在尝试让自定义Recycler View 适配器工作。我不太明白为什么它不起作用。我觉得奇怪的是自定义适配器的代码不执行(因为当我在那里放置断点时它不会中断)并且我确定我绑定(bind)了自定义
我想使用 Firebase 制作一个杂务应用程序,它有 2 个输入:描述和类。每当我运行该应用程序时,显示的屏幕都是空白的(标题除外)没有可能显示问题的明确指示或错误。这些是最富有成果的 logCat
我想使用 Firebase 制作一个杂务应用程序,它有 2 个输入:描述和类。每当我运行该应用程序时,显示的屏幕都是空白的(标题除外)没有明确的指示或错误可能显示问题。这些是最富有成果的 logCat
我是一名优秀的程序员,十分优秀!