why the session in iis automatically log out? - asp.net

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out.
and i debugged the website, i found no exception.
any one have ideas on this ?
Thanks in advance!

I assume the directory you are trying to delete is within the website folder.
When you delete a folder inside a website, then asp.net will restart resulting in loss of session state.
To avoid this problem
1) Try to implement out-of-process session state.
OR
2) Move the folder out of web application folder.

If you create, delete or change any directory or files underneath the web application directory while the app is running, ASP.NET unloads the appdomain thinking that the code has changed and needs to be reloaded. This clears all session state, etc. You'll need to move any file/directory create/delete/change stuff to a directory outside the web application directory.

Related

iis 7.5 app pool recycling has irritating behaviour

Now I have one irritating problem. I have Site which includes many web apps on asp.net 2.0 classic app pool. My app works with the next steps:
1) I recieve login form from server, input my credentials and send form.
2) When credentials are correct, my server starts to merge all configuration settings from mashine.config and web.config to one file ApplicationConfiguration.merged.xml which located in app root folder.
3) After that my app sends me page and I continue work with site. That's all.
But.. when I start my app first time after app_pool recycling(after time out or manual recycling) I have refreshing my app immediately after writing ApplicationConfiguration.merged.xml. After that my session is expired and I login again and my app works correctly.
ApplicationConfiguration.merged.xml locates in app root folder. When I switch off writing to this file or locate its to another folder (for example temp folder in app root folder) there all works correctly.
IIS refresh my app with next event:
Application_End
ChangeInGlobalAsax
_shutDownMessage=Overwhelming Change Notification in C:\inetpub\wwwroot\my_app_root_folder
Overwhelming Change Notification in C:\inetpub\wwwroot\my_app_root_folder
Change in GLOBAL.ASAX
HostingEnvironment initiated shutdown
CONFIG change
HostingEnvironment caused shutdown
So as I understand IIS thinks that I have changed important configuration files(web.config of Glabal.asax) and refreshes my app. But I don't use this file for anything - I only write current configuration information here. And why doesn't IIS refresh app everytime when I am logging because I am writting file each time after succesfull login but IIS refresh my app only after firt start.
Can I say IIS to ingnore ApplicationConfiguration.Merged.xml changes? I believe you can help me to understand this curious IIS behaviour. Thank's for your help.

ASP.NET: Writing web-accessible temp files without application restart

My ASP.Net application used to restart unpredictably during requests, ruining my state, session data etc. I determined that the problem was caused by a control that writes and deletes some files in Temp folder that it creates near bin folder, so the web directory looks like this:
bin
Temp
....
Default.aspx
web.config
ASP.Net apparently reacts to changes inside Temp folder the same way it reacts to changes inside bin or in web.config - it restarts the application.
I could partially solve the problem by moving the Temp outside the site directory. That way the application doesn't get restarted every time something temporary is written\deleted, so this part works well. The problem is that some of the files inside Temp directory should be web-accessible - like images generated on the fly and such.
So my question is actually threefold:
Should ASP.Net application get restarted even if the changes are made not in the bin directory, but in another directory at the same level? Or is there something wrong with my configuration?
Where and how do I create a temporary folder so it's web-accessible but it doesn't cause application restart?
How do I turn off restart on directory change from code or web.config (both in IIS and ASP.Net development server)?
Based on my understanding here is the answer to your questions:
ASP.NET restarts the application when too many files are changed in one of the content directories. For more info abt when app restart happens read: http://programming360.blogspot.in/2009/04/what-causes-application-restart.html
You can create the temporary folder anywhere in the same machine or on a different machine(file-share) so long as the IIS-User has access to the folder it should work normally. The only thing that you need to consider is the latency when the folder is on a different computer.
I dont believe you can control application restart and this is completely controlled by IIS. Might want to read up on this SO questions: ASP.NET restarts when a folder is created, renamed or deleted

ASP.NET Session & Delete Folders

I have a web app where the administrator can create news, pdf documents and other stuff in his cms panel.
The problem is when the admin delete a new or something else the app deletes all the files related to that new, I mean the images, pdfs and other documents. Tha main problem is those files are stored in folders under the "news" folder and when the app deletes them the session is lost.
How can I do to have a file system without losing the session?
I'd like that file system within the app folder...
Impossible for us to store those folders outside the app and we don't want to use StateServer because of the performanne....
Any other solution?
Thanks
Your session is lost becasue IIS recompiles. The easiest solution in my opinion is to store your files outside the wwwroot.
Discussed on SO: ASP.NET restarts when a folder is created, renamed or deleted
[Update]
Example:
Let's stay your app is in c:\inetpub\wwwoot\virtualdir1
You make a work directory:
c:\inetpub\inetwork
Give the proper rights (read/write/etc) to the Asp.net user of your app pool and it should all work like a charm.
More info on setting the rights: What are all the user accounts for IIS/ASP.NET and how do they differ?
Store the path to the workdirectory in your web.config (you no not want to hardcode it)
Having those files within the app folder is a poor desgin. The session is probably lost as you are causing IIS to recycle due to the file system changes. It is much safer to not have your web application able to write to its own folder, doing so is a security risk.
Separate your document folder and web site folder. And give right permission your document folder.

Remove temporary files web application

I'm developing a Web application, and there is a page when user must submit files which are saved into temporary folder on the server. If everything goes well, I send ajax request to the server to remove users uploaded file. But, if user closes the browser or shutdown the computer, I can't detect that.
In this case, what is the best way to gurantee that unused files are not stored forever? The site is developed in ASP.NET MVC and will be hosted on II7. Does IIS7 provides some configuration to deal with temporary files? Or I need to implement some service, which will be executed in a background with low priority and periodically check if there are "old" files to be removed?
Any help is very much appreciated.
I would have a windows service in the background to delete old files at some interval.

"Site is under construction" page for asp.net site

I have to implement ability to show "site is under construction" page during doing some maintenance work on site. There are a lot of ways to implement such behavior (using global.asax file, using IIS and so on). So I would like to know waht is the most used ways of impletenting this feature.
Thanks in advance.
I prefer App_Offline.htm file in the root.
Take a scrape of your site template, stick it in the App_Offline.htm file and place a message in it. Just dropping this file in the root folder of your web site effectively disables your site.
Meanwhile, upload/manage a second instance of the web-site using a temporary domain/URL and when tested/ready, re-point the old site to the new site in IIS.
The change you're deploying now is a simple change to a single page. But sometimes you deploy larger changes, or you deploy both code and database changes, and the site might behave incorrectly if a user requests a page before deployment is finished. To prevent users from accessing the site while deployment is in progress, you can use an app_offline.htm file. When you put a file named app_offline.htm in the root folder of your application, IIS automatically displays that file instead of running your application. So to prevent access during deployment, you put app_offline.htm in the root folder, run the deployment process, and then remove app_offline.htm after successful deployment.
Source: https://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-a-code-update

Resources