我的 global.asax 中有以下内容Session_Start
string myBrowser = Utils.SafeUserAgent(Request);
foreach (string bannedbrowser in BrowserBan.BrowsersToBan)
{
if (myBrowser.IndexOf(bannedbrowser, StringComparison.OrdinalIgnoreCase) > -1)
{
HttpContext.Current.Response.Redirect("/bannedBrowser.htm");
Session.Abandon();
break;
}
它可以防止转码器访问我的网站。但时不时地我得到一个错误说
System.Web.HttpException: Session state has created a session id, but cannot
save it because the response was already flushed by the application.
at System.Web.SessionState.SessionIDManager.SaveSessionID(
HttpContext context, String id, Boolean& redirected, Boolean& cookieAdded)
at System.Web.SessionState.SessionStateModule.CreateSessionId()
at System.Web.SessionState.SessionStateModule.DelayedGetSessionId()
at System.Web.SessionState.SessionStateModule.ReleaseStateGetSessionID()
at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
EventArgs eventArgs)
at System.Web.SessionState.SessionStateModule.OnEndRequest(Object source,
EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web
.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
仅当我尝试通过(例如)Google Transcoder 访问它时才会发生这种情况,但我想了解它为什么会发生以及如何防止它发生。
我必须放弃会话,以便在刷新用户代理时重新评估。