这是我得到响应的HTML
<html>
<head>
<title>Session state has created a session id, but cannot save it because the response was already flushed by the application.</title>
<meta name="viewport" content="width=device-width" />
</head>
<body bgcolor="white">
<span><H1>Server Error in '/DataService' Application.<hr width=100% size=1 color=silver></H1>
<h2>
<i>Session state has created a session id, but cannot save it because the response was already flushed by the application.</i>
</h2>
</span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.Web.HttpException: Session state has created a session id, but cannot save it because the response was already flushed by the application.<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
</code>
</td>
</tr>
</table>
<br>
<b>Stack Trace:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>
<pre>
[HttpException (0x80004005): Session state has created a session id, but cannot save it because the response was already flushed by the application.]
System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext context, String id, Boolean& redirected, Boolean& cookieAdded) +3235276
System.Web.SessionState.SessionStateModule.CreateSessionId() +54
System.Web.SessionState.SessionStateModule.DelayedGetSessionId() +80
System.Web.SessionState.SessionStateModule.ReleaseStateGetSessionID() +19
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +545
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
</pre>
</code>
</td>
</tr>
</table>
<br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1649.1
</font>
</body>
</html>
当我设置 customErrors mode =“ Off” 时,我会收到此错误,有时不是每次都出现
我还更改了 global.asax 文件并添加了以下功能,但无法解决问题
void Session_Start(object sender, EventArgs e)
{
string sessionId = Session.SessionID;
}
仍然出现相同的错误
这是.NET端的代码
public List<ReportSchedular> GetReportSchedular(string ID){
List<ReportSchedular> objuser = new List<ReportSchedular>();
try
{
DataSet Data = ReportSchedular.GetReportSchedular(ID);
if (((Data != null) && (Data.Tables.Count > 0)) && (Data.Tables[0].Rows.Count > 0))
{
foreach (DataRow row in Data.Tables[0].Rows)
{
ReportSchedular obj = new ReportSchedular
{
ID = ConvertToInt64(row["ID"]),
CompanyName = Convert.ToString(row["CompanyName"]),
CompanyID = Convert.ToString(row["CompanyID"]),
AutoRepeat = Convert.ToString(row["AutoRepeat"]),
Duration = Convert.ToString(row["Duration"]),
Email = Convert.ToString(row["Email"]),
UserId=Convert.ToInt64(row["UserId"]),
PeerCompanyIDs = Convert.ToString(row["PeerCompanyIDs"]),
ReportDate = String.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(row["ReportDate"])),
SchedulerEmail = Convert.ToString(row["SchedulerEmail"]),
PeersName = Convert.ToString(row["PeersName"]),
//last_sent = String.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(row["last_sent"])),
// below code for to handle a null values of 'last_sent'.
last_sent = String.Format("{0:MM/dd/yyyy}", !string.IsNullOrEmpty(row["last_sent"].ToString()) ? Convert.ToString(row["last_sent"]) : null),
};
objuser.Add(obj);
}
}
return objuser;
}
catch (Exception exception)
{
Common.AppendLog("Exception Message: " + exception.Message.ToString() + Environment.NewLine + "Stack Trace: " + exception.StackTrace.ToString() + Environment.NewLine + Environment.NewLine);
return objuser;
}
}