我开发了一个 web 应用程序,它将执行一些图像的幻灯片放映。我有这个应用程序的 jquery ajax web 方法调用
图像滚动完美......但一段时间后它停止了......我从日志中发现我的会话变量(这里是 Session [“用户名”])正在变为空。我的代码是
[WebMethod]
[ScriptMethod]
public static string GetNextImage()
{
try
{
if (HttpContext.Current.Session["Username"] != null)
{
string username = HttpContext.Current.Session["Username"].ToString();
RollingScreenBAL bal = new RollingScreenBAL();
DetailsForSlideShow[] details = bal.GetDetailsForSlideShow(username);
int count = details.Length;
int i;
for (i = 0; i < count; i++)
{
if (HttpContext.Current.Session["Count"] == null)
{
HttpContext.Current.Session["GraphUrl"] = details[0].GraphUrl;
HttpContext.Current.Session["Count"] = i + 1;
break;
}
else
{
if (Convert.ToInt32(HttpContext.Current.Session["Count"]) == i)
{
HttpContext.Current.Session["GraphUrl"] = details[i].GraphUrl;
if (i == (count - 1))
{
HttpContext.Current.Session["Count"] = null;
}
else
{
HttpContext.Current.Session["Count"] = i + 1;
}
break;
}
}
}
}
return HttpContext.Current.Session["GraphUrl"].ToString();
}
catch (Exception ex)
{
ConfigurationManager configMgr = new ConfigurationManager();
string traceFilePath = configMgr.GetTraceFilePath();
StreamWriter traceFile = new StreamWriter(traceFilePath, true);
traceFile.WriteLine(ex.Message + "\n" + ex.StackTrace + "Current User is " + **HttpContext.Current.Session["Username"])**;
traceFile.Close();
return ex.Message;
}
}
HttpContext.Current.Session["Username"]) 会话值正在变为空..谁能帮我为什么它会变为空?提前致谢...