C# 会话Sql数据库关闭时如何重定向到ASP.NET错误页

C# 会话Sql数据库关闭时如何重定向到ASP.NET错误页,c#,asp.net,iis,C#,Asp.net,Iis,我有一个ASP.NET网站,它在SQL Server中存储会话。我故意使会话数据库脱机,以确保向用户显示我的错误页面 My Web.config: <system.webServer> <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace"> <remove statusCode="404" subStatusCode="13" /> <error s

我有一个ASP.NET网站,它在SQL Server中存储会话。我故意使会话数据库脱机,以确保向用户显示我的错误页面

My Web.config:

 <system.webServer>
  <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
    <remove statusCode="404" subStatusCode="13" />
    <error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" path="LargeFileError.aspx" responseMode="Redirect" />
      <remove statusCode="500" />
      <error statusCode="500" path="Error.aspx" responseMode="ExecuteURL"/>
  </httpErrors>
 </system.webServer>

 <system.web>
  <customErrors mode="On" defaultRedirect="/Error.aspx" redirectMode="ResponseRewrite">    
    <error statusCode="500" redirect="Error.aspx" />
  </customErrors>
</system.web>
My Error.aspx页面是一个简单的页面,只有一个本地化字符串。因此,将无法使其成为html页面

我不断发现这个错误:

“基础提供程序在打开时失败。”

您可能会说,对于这个错误,有很多关于堆栈溢出的解决方案,但我这里的问题是显示错误页面(会话db关闭时的aspx页面),而不是解决这个错误

即使在直接导航到error.aspx页面时,也会出现此错误。 我需要一种方法来告诉Asp.Net和IIS我不需要这个特定页面的会话信息


如何解决此问题并确保显示我的错误页。

在现有连接字符串中删除“user Instance=true”并正常工作。

详情如下:
所以我做了以下几件事:

1) 更改响应。重定向到Global.asax中的服务器。传输

2) 在Error.aspx的@Page指令中添加了此设置

EnableSessionState="false"
3) 我还必须管理我的站点。Master(Error.aspx是一个子页面)有一个反Xsrf验证,它抛出了一个错误

  if (Context.User != null)
                {
                    ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty;
                }
                else {
                    ViewState[AntiXsrfUserNameKey] = String.Empty;
                }

我不需要解决错误消息,因为我故意使数据库脱机。我希望用户被重定向到我的错误页面。
  if (Context.User != null)
                {
                    ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty;
                }
                else {
                    ViewState[AntiXsrfUserNameKey] = String.Empty;
                }