简体   繁体   English

响应重定向使session_end在全局asax中

[英]response redirect makes session_end in global asax

I am getting frustrated due to the session become null. 由于会话为空,我感到沮丧。
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: 当我单击保存按钮时,我将数据从后面的代码保存到数据库,如果成功,我将使用语法将用户重定向到主项目页面:

Response.Redirect("~/Admin/Projects.aspx?i=esc&prjName=abc",'false');

but its make my session null. 但它使我的会话为空。
Its goes to Globex.asax page ang executes the Session_End and make all session null. 它进入Globex.asax页,并执行Session_End并使所有会话为空。

I even tried Server.Transfer but by this the browser url remains same and client doesn't want this.Even some where I read that the Server.Execute is also used to redirect but it is showing some wrong results. 我什至尝试了Server.Transfer但是由此浏览器的URL保持不变,客户端也不希望这样做。甚至在我读到的Server.Execute也用于重定向的地方,但显示出了错误的结果。

can I use the Response.Redirect without this session null problem ?? 我可以使用Response.Redirect而没有此会话为null的问题吗?

(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.) (在此页面中,我正在创建文本文件来存储一些详细说明,如果成功,则将重定向到另一个页面。)

Update:: 更新::

here is my code for button click 这是我的按钮点击代码

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)
            {

            }
        }

Before you redirect to the next page, assign the existing session value in the button click event also. 在重定向到下一页之前,还要在按钮单击事件中分配现有的会话值。

This would solve the problem. 这样可以解决问题。

hope this will be helpful to you, ASP.NET Session becomes null after postback on local 希望这对您有所帮助, 本地回发后ASP.NET会话变为空

This think your problem is related to some kind of permission denial, which is nulling your session. 这认为您的问题与某种拒绝权限有关,这使您的会话nulling

There must be a problem in creating or saving the text file. 创建或保存文本文件时肯定存在问题。 This may be making Session_End call so you are getting all values null. 这可能是在调用Session_End,因此您将所有值都设置为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Global.asax.cs中的Session_Start和Session_End - Session_Start & Session_End in Global.asax.cs Global.asax.cs中的Session_End不触发 - Session_End in Global.asax.cs not firing 从global.asax中的Session_end重定向到另一个页面 - Redirecting to another page from Session_end in global.asax ASP.net MVC 5 - 如何从 Global.asax.cs 中的 session_end() 事件重定向到操作方法 - ASP.net MVC 5 - How to redirect to action method from from session_end() event in Global.asax.cs 会话变量值并非始终在Global.asax Session_end中可用 - Session variable value not always available in Global.asax Session_end 在数据库中注销日志并在Global.asax中的Session_End()后面删除cookie - With LogOff record in database and deleting cookie behind the Session_End ( ) in Global.asax 基类如何从Global.asax调用Session_End方法? - How does the baseclass call the Session_End method from Global.asax? Global.asax.cs中的Session_End未使用表单身份验证触发 - Session_End in Global.asax.cs not firing using forms authentication ASP.NET MVC4 - Session_End - 如何在Global.asax的Session_End中获取当前登录用户的名称? - ASP.NET MVC4 - Session_End - How can I get the currently logged on user's name in Session_End of Global.asax? 自定义session_end重定向实现? - custom session_end redirect implementation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM