title: response redirect makes session_end in global asax
body: <p>I am getting frustrated due to the session become null.<br/>When I click on save button I save the data to DB from code behind and if this successfully I am redirecting the user to the main projects page,using syntax:</p>
  
  <pre><code>Response.Redirect("~/Admin/Projects.aspx?i=esc&amp;prjName=abc",'false');
  </code></pre>
  
  <p>but its make my session null.<br/>Its goes to Globex.asax page ang executes the <code>Session_End</code> and make all session null.</p>
  
  <p>I even tried <code>Server.Transfer</code> but by this the browser url remains same and client doesn't want this.Even some where I read that the <code>Server.Execute</code> is also used to redirect but it is showing some wrong results.</p>
  
  <p>can I use the <code>Response.Redirect</code> without this session null problem ??</p>
  
  <p>(In this page I am creating the text file to store some long description and if this is successful then I am redirecting to the another page.)</p>
  
  <p><strong>Update::</strong></p>
  
  <p>here is my code for button click</p>
  
  <pre><code>protected void lnkbtnAddDescription_Click(object sender, EventArgs e)
          {
              try
              {
                  if ((!hidProjId.Value.ToString().Equals("") || !hidEditProjId.Value.ToString().Equals("")) &amp;&amp; !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("&lt;br /&gt;", "&lt;p&gt;");
                          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&amp;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&amp;prjName=" + proj.ProjectName.ToString());
                          }
                          else
                          {
                              //Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&amp;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&amp;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("&lt;br&gt;", "&lt;p&gt;");
                          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&amp;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&amp;prjName=" + proj.ProjectName.ToString());
                          }
                          else
                          {
                              //Server.Execute("~/SuperAdmin/Projects.aspx?i=sc&amp;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&amp;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)
              {
  
              }
          }
  </code></pre>