Session Sql数据库关闭时如何重定向到ASP.NET错误页面
我有一个ASP.NET网站,它在SQL Server中存储会话。 我故意使我的会话数据库脱机,以确保我的错误页面显示给用户。
我的Web.config:
我的global.asax:
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); Server.ClearError(); Response.Redirect("Error.aspx"); }
我的Error.aspx页面是一个只有本地化字符串的简单页面。 因此,将无法使其成为html页面。
我继续收到此错误:
“底层提供商在Open上失败了。”
你可能会说这个错误的堆栈溢出有很多解决方案,但我的问题是显示错误页面(会话数据库关闭时的aspx页面)而不是解决此错误。
即使我直接导航到error.aspx页面,我也会收到此错误。 我需要一种方法告诉Asp.Net和IIS,我不需要这个特定页面的会话信息。
如何解决此问题并确保显示我的错误页面。
在现有的连接字符串中删除“user Instance = true”并且它有效。
详情请见: http : //blogs.msdn.microsoft.com/dataaccesstechnologies/2012/08/09/error-the-underlying-provider-failed-on-open-in-entity-framework-application/#comment-17785
所以我做了这些事:
1)将Respose.redirect
更改为Global.asax中的Server.Transfer
2)在Error.aspx的@Page指令上添加了此设置
EnableSessionState="false"
3)我还必须管理我的site.Master(Error.aspx是一个子页面)有一个Anti Xsrfvalidation,它抛出了错误。
if (Context.User != null) { ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty; } else { ViewState[AntiXsrfUserNameKey] = String.Empty; }