首页 > 解决方案 > 当 post call 进入 webform 应用程序中的页面时,会话被重置

问题描述

我有一个基于 ASP.Net 4.7 的 webform 应用程序,要求在某个页面上我需要使用一些参数将表单提交到我的应用程序外部的 url(外部 URL),我需要发送一个返回 url(它将是我的应用程序的当前页面),在该应用程序(外部 URL)上运行的应用程序将处理来自表单的数据,并重定向到返回 url,现在的问题是何时在我的应用程序会话中收到该 post 回调被重置和所有数据都丢失了,我可以在上下文中看到会话 ID 与以前不同,并且由于我的验证,我的应用程序将其重定向到登录页面。任何人都可以帮助为什么我的会话被重新生成。

这些是我的 web.config 设置。

    <sessionState 
  mode="InProc" 
  timeout="200" 
  cookieless="false" 
  cookieSameSite="Lax"
/>

这就是我发布数据的方式。

System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, "POST", ExternalUrl));
System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", "Var1", Var1));
System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", "ReturnUrl", CurrentApplicationUrl));
System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", "Var2", Var2));
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");

HttpContext.Current.Response.Flush(); // 
HttpContext.Current.Response.SuppressContent = true;  
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

标签: asp.netwebformshttp-postsession-cookiessession-state

解决方案


我有同样的问题。经过多天的反复试验,我发现 IIS Express 使用的 localhost 证书与我的本地 IIS 使用的证书之间存在证书冲突。我必须从“个人”/“证书”文件夹和 MMC 中的“受信任...”/“证书”文件夹中删除 RSA 颁发的证书(以管理员身份运行)。代码很好。冲突是两个证书都在认证“localhost”。希望这可以帮助。


推荐阅读