如果你发现session突然无理由的丢失,而当你认真的检查代码并且排除其它常规可能丢失
的可能性时,你可能会像我一样,几乎要接近崩溃~!
后来发现问题出在我用代码创建一个临时目录然后删除临时目录的删除操作上。

现在和大家分享下:希望对碰到类似钉子的朋友有用。。

说白了session丢失实质就是:应用程序重起!

应用程序什么时候自动重起呢?

请参考:Anand在dotnetindia.com发表的文章

原文引用
{
Why ASP.NET Restarts?
Found this link from one of the blogs I was browsing today. This is ASP.NET Forum post by Patrick Y. Ng of MS.

This talks about both 1.0 and 1.1

This behaviour has been bugging lots of people. ASP.Net will restart its application for various reasons. All these reasons are legitimate, but the side effect is that the application will reset all its cache, application state, and InProc session states. 
You can detect the restart of application and worker process by using the performance monitor. The counters to monitor are "ASP.NET\Application Restarts" and "ASP.NET\Worker Process Restarts". 

For worker process restart, ASP.NET will write an entry in the eventlog to explain why (logLevel in controls how often eventlog is written). 

For application restart, however, in v1 and v1.1 there is no easy way for a customer to figure out why a restart happened. 

So by listing all reasons for app restart, I hope I can help some customers to understand and avoid the restart. 

For v1 
------ 

{
Things that causes application restart: 

- The max compilation limit is reached (look for numRecompilesBeforeApprestart in machine.config) 

- Physical application path of the web application has changed. 

- Change in global.asax or one of the included files 

- Change in machine.config 

- Change in web.config in the app root 

- Change inside bin directory or its subdirs 

- A directory is renamed to bin, or bin is created 

- Overwhelming change notifications – too many files are changed too fast in one of content directories – could happen if, for example, files are generated on the fly per request 

- Change in the code-access security policy file 
}

- The settings of various attributes in in machine.config affect the restart/shutdown of the worker process itself. However, if you use Windows 2003, and (by default) you are NOT using IIS5 isolation mode, is ignored. Instead, the settings in "Application Pools" in IIS manager is used. 


For v1.1 
-------- 
The list for v1.1 is the same as v1, with the following new conditions: 

{
- User code called HttpRuntime.UnloadAppDomain 

- Any directory under the web application folder is renamed 
}
IIS 6.0 
-------- 
If you're using IIS 6.0, and you're not using IIS 5 compatible mode, then aspnet_wp.exe will be replaced by w3svc.exe. You may want to go to IIS Manager, go to Application Pools/DefaultAppPool, and see if any of the parameters on the Recycling and Performance tabs are causing the IIS worker process (w3svc.exe) to shutdown. 
}

也就是说 asp.net 会监视应用程序目录,一但有被监视
的动作发生(比如:修改了config、重命名目录等)应用程序就会自动重起
当然这时你的session一定丢失了。

如果避免不了这种操作(如:重命名目录);这里我们可以用cookie存信息或存到数据库去;

注意:除了以上列出的英文条件外。目录的删除操作一定丢失session。asp.net的内部机制对待目录有点像个守财奴,它死守着目录,你创建它不会管(往里加),一但创建他就会监视该目录,若你要删除或重命名它的(动它的目录),它就发生重起了。。

转载于:https://www.cnblogs.com/qqcrazyer/archive/2007/01/27/632075.html

小心!目录删除及重命名操作 ,一定丢失Session~~!相关推荐

  1. python列重命名_Python目录–创建,重命名,删除,列出,更改

    python列重命名 Good day, learners! In this tutorial we are going to learn about Python Directory. In our ...

  2. java对文本文件进行操作:读取、修改、添加、删除、重命名等

    java对文本文件进行操作:读取.修改.添加.删除.重命名等 Java IO 也称为IO流,IO = 流,它的核心就是对文件的操作,对于 字节 .字符类型的输入和输出流. IO是指对数据流的输入和输出 ...

  3. [CentOs7]搭建ftp服务器(3)——上传,下载,删除,重命名,新建文件夹

    摘要 上篇文章介绍了如何为ftp添加虚拟用户,本篇将继续实践如何上传,下载文件. 上传 使用xftp客户端上传文件,如图所示 此时上传状态报错,查看详情 从错误看出是应为无法创建文件造成的.那么我们就 ...

  4. 点更改计算机名闪退,我用win10电脑在编辑文件夹如删除,重命名之类时他会黑一下然后闪退,正常吗,怎么解决?,word一保存就闪退...

    !!!word又bug了,为啥我写完的东西点了保存word就闪退啊?然后保存在桌面上的文档打不开, 第一种可能:你直接点保存-确定,保存在我的文档里面了.去我的文档里找. 第二种可能中病毒,被隐藏或者 ...

  5. linux 移动剪切命令,Linux移动剪切文件和目录命令-Linux重命名文件和目录命令-Linux mv命令详解-嗨客网...

    Linux移动或重命名文件或目录(mv)教程 在 mv 命令会根据第二个参数类型的不同(是目标文件还是目标目录),将文件重命名或将其移至一个新的目录中.当第二个参数类型是文件时,mv 命令完成文件重命 ...

  6. Git查看、删除、重命名远程分支和tag【转】

    转自:http://zengrong.net/post/1746.htm 本站文章除注明转载外,均为本站原创或者翻译. 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也 ...

  7. Linux CentOS删除或重命名文件夹和文件的办法

    Linux.CentOS操作系统下如何删除和重命名文件夹呢?办法如下: 一.Linux.CentOS下重命名文件和文件夹 mv:move 用移动文件命令就可以了,因为linux系统没有专门的重命名命令 ...

  8. python移动文件到另一个文件夹若有同名文件更改文件名_Python 创建、复制、移动、删除和重命名文件和文件夹...

    我们本文学习使用Python对电脑文件和文件夹进行操作,包括创建.复制.移动.删除和重命名等操作. os.mkdir() 创建文件夹 # 引入 os 模块,下面的代码都默认已引入 os.path.ex ...

  9. Python-文件和文件夹的移动、复制、删除、重命名

    转自:http://blog.csdn.net/woshisangsang/article/details/74360612 #文件.文件夹的移动.复制.删除.重命名#导入shutil模块和os模块 ...

最新文章

  1. pretty_errors_python
  2. linux locale文件,Linux 怎样修改locale语言设置
  3. 服务模拟-ServiceMock
  4. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】
  5. java io 读取配置文件_java读取配置文件 - tomzhao2008的个人空间 - OSCHINA - 中文开源技术交流社区...
  6. eclipse制作uml_Eclipse生成一个UML
  7. WPF的样式(Style)继承
  8. mac php命令行模式,phpstorm分别在Mac和Windows下启动命令行,并启用ssh
  9. Oracle EBS连接数不足
  10. nodejs 批处理执行 app.js
  11. 打印机 计算机 usb,电脑没法识别打印机(USB接口)
  12. Docker从入门到实战(二)
  13. 基于HTML5 Canvas实现炫酷钟表效果
  14. JEECG3.8 全套实战视频全部开放,免费下载!
  15. 优化ESD防护的PCB设计准则
  16. 【文献阅读】 Sorghum segmentation by skeleton extraction
  17. Android计算器功能的实现
  18. jacoco—增量代码覆盖率实现
  19. onmouseover 、onmouseout和onmouseenter、onmouseleave的区别-简记
  20. pstack命令使用说明

热门文章

  1. node中使用es6/7/8 --- 支持性与性能
  2. 【UWP】拖拽列表项的排序功能实现
  3. jq的ajax和模块引擎
  4. OpenStack镜像制作笔记 --以windows8.1-amd64为例
  5. 利用Python的三元表达式解决Odoo中工资条中城镇、农村保险的问题
  6. [原]如何做一份精致的性能测试报告?
  7. IDE to AHCI/RAID 蓝屏补丁
  8. 30天敏捷结果(4):放弃一些事情
  9. Struts2升级注意事项
  10. VS集成环境中的JavaScript脚本语法检查