由于会话变为空,我感到沮丧。
当我单击保存按钮时,我将数据从后面的代码保存到数据库,如果成功,我将用户重定向到主项目页面,使用语法:
Response.Redirect("~/Admin/Projects.aspx?i=esc&prjName=abc",'false');
但它使我的会话无效。
它转到 Globex.asax 页面并执行Session_End
并使所有会话为空。
我什至尝试过Server.Transfer
,但是浏览器 url 保持不变,客户端不想要这个。即使我读到的一些地方Server.Execute
也用于重定向,但它显示了一些错误的结果。
我可以使用Response.Redirect
没有这个会话的空问题吗?
(在这个页面中,我正在创建文本文件来存储一些长描述,如果成功,那么我将重定向到另一个页面。)
更新::
这是我的按钮点击代码
protected void lnkbtnAddDescription_Click(object sender, EventArgs e)
{
try
{
if ((!hidProjId.Value.ToString().Equals("") || !hidEditProjId.Value.ToString().Equals("")) && !txtDescription.Value.ToString().Equals(""))
{
//ProjectDescription
int projId = 0;
if (!hidIsEdit.Value.ToString().Equals(""))
{
projId = Convert.ToInt32(hidEditProjId.Value.ToString());
}
else
{
projId = Convert.ToInt32(hidProjId.Value.ToString());
}
ProjectM proj = new ProjectM();
proj.LoadByKey(projId);
string prj = proj.ProjectName.ToString().Replace(" ", "-");
string strDirectoryPath = Server.MapPath("~/ProjectDescription/") + proj.ProjectId + "-" + prj;
if (!Directory.Exists(strDirectoryPath))
{
Directory.CreateDirectory(strDirectoryPath);
string filePath = strDirectoryPath + "/" + proj.ProjectId + "-" + prj + ".txt";
string strDescription = txtDescription.Value.ToString().Replace("<br />", "<p>");
createTextFile(filePath, strDescription);
string dbDirectoryPath = "~/ProjectDescription/" + proj.ProjectId + "-" + prj + "/" + proj.ProjectId + "-" + prj + ".txt";
proj.Description = dbDirectoryPath.ToString();
proj.IsNew = false;
proj.Save();
if (!hidIsEdit.Value.ToString().Equals(""))
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString() + "",false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString());
}
else
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString() + "",false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString());
}
}
else
{
Directory.Delete(strDirectoryPath, true);
Directory.CreateDirectory(strDirectoryPath);
string fileName = proj.ProjectName.ToString().Replace(" ", "-");
string filePath = strDirectoryPath + "/" + proj.ProjectId + "-" + fileName + ".txt";
string strDescription = txtDescription.Value.ToString().Replace("<br>", "<p>");
createTextFile(filePath, strDescription);
string dbDirectoryPath = "~/ProjectDescription/" + proj.ProjectId + "-" + proj.ProjectName.ToString() + "/" + proj.ProjectId + "-" + proj.ProjectName.ToString() + ".txt";
proj.Description = dbDirectoryPath.ToString();
proj.IsNew = false;
proj.Save();
if (!hidIsEdit.Value.ToString().Equals(""))
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString() + "", false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=esc&prjName=" + proj.ProjectName.ToString());
}
else
{
//Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString() + "", false);
Session["dsProj"] = null;
Session["editProjId"] = null;
Session["fname"] = hidFname.Value.ToString();
Session["UserId"] = hidUserId.Value.ToString();
Session["role"] = hidRole.Value.ToString();
Response.Redirect("~/SuperAdmin/Projects.aspx?i=sc&prjName=" + proj.ProjectName.ToString());
}
}
}
}
catch (Exception)
{
}
}
private void createTextFile(string filePath, string strDescription)
{
try
{
StreamWriter w = File.CreateText(filePath);
w.WriteLine(strDescription);
w.Flush();
w.Close();
}
catch (Exception ex)
{
}
}