<p>I have deployed ASP.NET web site and ASP.NET web service on the same web server. Both of them require access to shared file. </p>

<p>How to implement/share lock that supports single writers and multiple readers? If somebody reads, nobody can write, but all still can read. If somebody writes, nobody can read/write.</p>

to open file for writing with allowing other threads to read it use System.IO.File.Open method with System.IO.FileShare.Read. Ie.:
```
```
System.IO.File.Open("path.txt",System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.ReadWrite,System.IO.FileShare.Read)
```
```
Other (reading) threads should use System.IO.FileAccess.Read
Signature of Open method:
```
```
public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share);
```
```
UPDATE 
If you need all instances to ocasionally write to file. Use Mutex class to reserve file writing. Ie.:
```
```
Mutex mut = new Mutex("filename as mutex name");
    mut.WaitOne();
    //open file for write, 
    //write to file
    //close file
    mut.ReleaseMutex();
```
```
Hope it helps.