I'm hoping someone can help me understand a process of recycling a webservice using the following method:
At the company where I work, the process is to simply open up the web.config file in an editor, make any kind of modification, and then save the file. The modification can be as simple as entering a space after the last xml node and then removing it.
I'm curious, but how does this end up "recycling the webservice"?
ASP.NET has a file system watcher on the config file. From there it boots the application from the app pool/app domain.
A better practice would to set up different app pools and recycle them from IIS.
Updating the web.config actually recycles the application pool for the web services/sites. It also clears out the application cache and session variables if used InProc.
This isn't the recommended approach though because if you make an oopsie then your webservice won't come back up. Its better to go to the IIS application pool manager and recycle it from there.
Related
I have a website that constantly scans a folder for files and then performs some actions on them. I dropped several thousand of these files into the directory, it started chugging but when I came back in the morning there were still files there. When I opened up a new session it started working again. Is it possible to keep this function running without a user having a session open?
in IIS, remove the session expiration time on both the website and the application pool. This means that once you fire/lookup the site once, it never shuts down. But as #Yuriy mentioned, what you're doing shouldn't be done via a website... get the information/perform your tasks using a windows service, and if need be, implement a way to display the tasks that were done in a website. But the web site shouldn't be doing the heavy lifting.
Session is user-specific.If you do not want session state enabled for your application, you can set the session mode to Off. please refer this msdn post.
Try using Quartz.net. It is a scheduler that will run tasks for you.
I have a text file that contains cached data in JSON format. I'm trying to update the file, but my IIS worker process is locking the file and when I try to write to it, I get the error "The Process Cannot Access The File Because It Is Being Used By Another Process". I've searched for answers on Google and Stack, but I can't seem to find anything related to IIS locking a file. The text file is included in my Visual Studio solution and I am using IIS on my local machine to host my website. For my first question, I'm wondering how I can get IIS to release the file or not lock it at all. For second question, I'm wondering if there's a different approach to prevent IIS from locking my files.
IIS is not locking your file. IIS has no idea your file exists. Some application, probably your own, is locking the file.
Try using a program like procmon from SysInternals to find out which process is locking the file.
After taking a lunch break, I realized that the worker process was hanging on to the text file because it was reading a line from it and then attempted to write to it. I wrapped the file in a using statement and moved the write after the read and now it's working.
I had a similar problem (file locked by IIS worker process) when attempting to publish a .NET Core API app.
In case it helps anybody, my issue was caused by a related application, which was calling the API, being in debug mode when attempting to publish the API.
I was able to fix the problem by having the app pool recycle after each request. Go to the Advanced Settings of your app pool. Under Recycling, set request limit to 1.
We've got a process currently which causes ASP.NET websites to be redeployed. The code is itself an ASP.NET application. The current method, which has worked for quite a while, is simply to loop over all the files in one folder and copy them over the top of the files in the webroot.
The problem that's arisen is that occasionally files end up being in use and hence can't be copied over. This has in the past been intermittent to the point it didn't matter but on some of our higher traffic sites it happens the majority of the time now.
I'm wondering if anyone has a workaround or alternative approach to this that I haven't thought of. Currently my ideas are:
Simply retry each file until it works. That's going to cause errors for a short time though which isn't really that good.
Deploy to a new folder and update IIS's webroot to the new folder. I'm not sure how to do this short of running the application as an administrator and running batch files, which is very untidy.
Does anyone know what the best way to do this is, or if it's possible to do #2 without running the publishing application as a user who has admin access (Willing to grant it special privileges, but I'd prefer to stop short of administrator)?
Edit
Clarification of infrastructure... We have 2 IIS 7 webservers in an NLB running their webroots off a shared NAS (To be more clear, they're using the exact same webroot on the NAS). We do a lot of deploys, to the point where any approach we can't automate really won't be viable.
What you need to do is temporary stop IIS from processing any incoming requests for that app, so you can copy the new files and then start it again. This will lead to a small downtime for your clients, but unless your website is mission critical, that shouldn't be that big of a problem.
ASP.NET has a feature that targets exactly this scenario. Basically, it boils down to temporarily creating a file named App_Offline.htm in the root of your webapp. Once the file is there, IIS will takedown the worker process for you app and unload any files in use. Once you copy over your files, you can delete the App_Offline.htm file and IIS will happily start churning again.
Note that while that file is there, IIS will serve its content as a response to any requests to your webapp. So be careful what you put in the file. :-)
Another solution is IIS Programmatic Administration.
Then you can copy your new/updated web to an alternative directory then switch the IIS root of your webapp to this alternative directory. Then you don't matter if files are locked in the original root. This a good solution for website availability.
However it requires some permission tuning...
You can do it via ADSI or WMI for IIS 6 or Microsoft.Web.Administration for IIS 7.
About your 2., note that WMI don't require administrator privileges as ADSI do. You can configure rights by objects. Check your WMI console (mmc).
Since you're already load balancing between 2 web servers, you can:
In the load balancer, take web server A offline, so only web server B is in use.
Deploy the updated site to web server A.
(As a bonus, you can do an extra test pass on web server A before it goes into production.)
In the load balancer, take B offline and put A online, so only web server A is in use.
Deploy the updated site to web server B.
(As a bonus, you can do an extra test pass on web server B before it goes into production.)
In the load balancer, put B back online. Now both web servers are upgraded and back in use in production.
List item
You could also try to modify the timestamp of web.config in the root folder before attempting to copy the files. This will unload the application and free used files.
Unless you're manually opening a handle to a file on your web server, IIS won't keep locks on your files.
Try shutting down other services that might be locking your files. Some examples of common services that do just that:
Windows Search
Google Desktop Search
Windows Backup
any other anti-virus or indexing software
We had the same server (2003) and the same problem. Certain dll's were being locked and putting the App_Offline.htm in the website root did jack diddly for us.
Solution:
File permissions!
We were using a web service which runs under the Network Service account or the IIS_WPG account to deploy updates to the web site. Thus it needed write access to all the files. I already knew this, and had already set the permissions on the directory a while ago. But for some strange reason, the necessary permissions were not set on this one problem dll. You should check the permissions not only on the directory, but on the problem file as well.
We gave Network Service and IIS_WPG users read/write access to the entire web root directory and that solved our file in use, file locked, timeout, and access denied issues.
I have a web service on iis that i'm calling in a simple console app
this web service is takes stuff out of a database
I changed the data base on a config file but it seems to still be calling the former data base
any tip?
If there are some cached database credentials within the application, simply recycling the application pool for which it is in will flush that out. If you're not familiar with the application pools, simply restart IIS and that will do the same thing.
If you don't have credentials cached, could you specify where the credentials are being stored, such as a web.config file, custom library, etc?
Make sure that the connection string is actually being used rather than it using the settings from the original dataset designer.
If you have used the dataset designer there will be a connection string setting in the settings file of the project. unless the connection string in your web.config is exactly the same then it will use the original.
You can check whether it is using the string you supplied by entering garbage in the web.config connection string and seeing if the webservice fails after you have restarted the website.
Hope that helps.
It's hard to offer this advice without sounding unhelpful, but in cases like these you just have to track through it, logging out the various important bits, like what connection string your components are using when they connect to the database, etc, and the answer will sooner or later come to light. I say this from experience.
There's not much that myself or other posters here can do but offer you the most general advice, like recycling the application pools. Your question is just too short and lacking in information, and the subject of web services is a very wide one.
So start by adding logging as I suggested and it might just work, or at least give us more to go on. All the best to you..
Are you setting the connection string in the client app.config or the web services web.config?
I'm looking for a c# snippet which I can insert in a Windows service. The code must empty the recycle bin for all users on the computer.
I have previously tried using SHEmptyRecycleBin (ref http://www.codeproject.com/KB/cs/Empty_Recycle_Bin.aspx) however the code doesn't work when ran from a windows service as the service is running with local system privileges.
Hopefully you can't.
A service running as the local machine should not be clearing my Recycle bin, ever.
You could promote the service to run as an Admin account then it would have the right (and be a security risk), but why do you want to do this? It sounds like the sort of think Viruses try to do.
I think doing something like this is against Microsoft recommended practices. What are you trying to do that requires emptying the Recycle Bin from a Windows service?
First, have you tried running the service on an interactive user account? Maybe SHEmptyRecycleBin requires an interactive user even though it doesn't necessarily display a Window.
Second, I'm not sure it's a good idea to delete other users' stuff but I guess you have a very good reason?