Session variable object deleted on postback - ASP.NET

I did something like the following code:

protected void Page_Load(object sender, EventArgs e)
{
   Label1.Text = Session["loginid"].ToString();
}

protected void delete_click(object sender, EventArgs e)
{
    delete("mail1",Session["loginid"]);
}

private int delete(string mailid, string user)
{
 System.IO.Directory.Delete(Server.MapPath(@"~\files\" + user + @"\" + mailid), true);
}

When I click the delete button, everything works fine and the folder is deleted. but after that, when the page returns again, NullRefrenceException Label1.Text = Session ["loginid"] exception. ToString ();

Why is this happening...??

When I do not use this Directory.Delete () method, everything works fine and the session variables are not null.

When I traced my application, I found that after the Directory.Delete () method, the session variables were intact, and I was able to use these session variables in processing after Directory.Delete ().

, null. , delete().

, , . Visual Studio.

, .

+3
6

, , , , - ( Server.MapPath ~). IIS, , , , .

, web.config, - , . , , IIS ?

, , , ( ), IIS . , -, , .

+2

"files" -? , . sessionStateServer. .

Web.config:

<configuration>
    <system.web>
        <sessionState mode="StateServer"></sessionState>
    </system.web>
</configuration>
+1

, . , ( ) StateServer .

+1

, , , -, Session["loginid"].ToString(). , Session["loginid"]? , , , loginid .

, , HTTP-, . . .

0

.delete() , ,

, , . ( . : )

, - , , . , , .

, , Global.asax Application_OnError Session_OnStart ( ). , , .

0

-, :

  • ?
  • ASP.NET, App_Data App_Code, ?

:

  • . , Directory.Delete . , ?
  • Use a tool such as Fiddler to check cookies exchanged between the browser and the web server during postbacks. Make sure that when a browser first visits a new session, a cookie is created and saved in the browser. Then, by deleting the folder, verify that the web server sends a new session cookie in response to this postback. This would mean that a new session was created.

thank

0
source

Source: https://habr.com/ru/post/1733693/


All Articles