Can not overwrite file in virtual directory - asp.net

I'm having problems with a site using a virtual directory to share images between three load balanced web servers.
The three web servers all have an asp.net website installed using IIS 7.5 and a virtual directory pointing to the same shared folder. There is no problem reading the images.
The problem is that the windows service that is downloading images and writing to the shared folder gets the exception, "The process cannot access the file 'D:\WebShare\images\440.jpg' because it is being used by another process".
Is there any way to "force" an overwrite? Or should I rethink my solution? It must be a very common scenario that multiple web servers share a folder and some other process updates the files in that folder but I can't find a solution to my problem.

So I've solved the problem. I have another service running on each server copying the images to a local folder instead of each server reading the images from the same shared folder.
My guess is that the problem has something to do with the fact that an IIS website was reading from a shared folder on another server. The only difference now is that the website is reading from a local folder. I still have a windows service overwriting images in that folder.

Related

folder explorer for server files

Is it possible to rename/move or delete files from a web application (ASP.Net MVC) that are on a server folder just like how you would do it locally? I would want the user to be able to upload say 30 files (from a scanner auto-feed) into a temporary folder on the server (cannot save it locally due to data security) and then allow the user to be able to rename /move before uploading them onto Azure blob storage.
I saw few examples - jquery file tree seemed good but not sure if it allows rename and moving. Please suggest solutions for working with the server folder. I intend to delete the server folder after I am done transferring files to Azure. TIA.
Yes, you can do this by giving the USER that is running the ASP.Net application (defaults to IUSR) permissions to write to that folder.
Be very careful though, as you're potentially opening your website for abuse when doing this.
See: https://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis for how IIS users operate.

How to setup error page handling for subdomains?

On my hosting server I want to achieve the following arhitecture of main site and subdomains:
www.site.com
subdomain1.site.com
subdomain2.site.com
All three domain have some common resources: scripts, css files, images and custom error files to present errors like 404, 503 in a creative intriguing and most entertaining way.
I have organized folders on my hosting server into this structure
www-main
www-subdomain1
www-subdomain2
shared-css
shared-errors
I have setup each subdomain as an asp.net applicatin which resides in its physical folder.
To access common shared resources I have created virtual folders for each subdomain that point to the sam physical folders.
virtual folder shared-css in subdomain1 points to shared-css physical folder
virtual folder shared-css in subdomain2 points to shared-css physical folder
This works ok. But not for folder containing error files. I have configured my web.config and files according to http://benfoster.io/blog/aspnet-mvc-custom-error-pages
The problem is that it does not work for subdomains. If I configure virtual folder as asp.net application it complains it cannot load assemblies for the application for which this folder was created. On the other hand if I configure it as ASp folder it simply does not work.
This same concept works if site is not divided into subdomains but into subfolders instead of subdomains.
Does anybody has a working solution for this problem?
Not suggestions, I have tried many things, anything I could think of.

Questions about copy IIS config files to another server

I have several asp.net web services is running in IIS. Now I want to move to another server in all exactly same IIS setting and using same web services. I know about copying a IIS config files(ApplicationHost & administration) to new server remotely but do I also need to copy all asp.net files to new server as well? If yes then must the asp.net files be in the same file path directory as the current one(D:\Website) for IIS in new server to be able to recognize it?
Yes, you would need to copy the ASP.NET files as well.
It is not necessary to put them in the same file path directory. Whatever directory you put them in, ensure your IIS Website Settings point to that directory and you have setup the same set of permissions etc. on it.
e.g. You could have had a website on c:\site on one web server. you could move the website files onto another web server and put them on d:\newsite\ and change the Website Directory Path in IIS Manager to point to D:\newsite\ directory.

Same virtual (global) directory for multiple websites

I am working on multiple websites in asp.net mvc. Some websites are top level domains and some are subdomain but all these websites are hosted on same server.
www.foo.com
subfoo.foo.com
www.abc.com
a.abc.com
I want all these websites should access same directory for save and retrieve some files in this way i can manage files efficiently.
www.foo.com/assets
subfoo.foo.com/assets
Currently every website is handling data its own wwwroot directory so when i need these files on different website then i have to do lot of work for retrieval.
For this purpose i have created folder out side the websites directory and point out as virtual directory in one websites. I tried to repeat same process for other websites but can 't do this because hosting server does not permit me to point out virtual directory on same folder.
So my question is this limitation of IIS. Is there any other technique to do this task in better way?
Virtual directory is the only way I know of to do what you ask. It sounds odd that you have a limitation of one virtual directory pointing to the same folder, maybe you need a new host.
EDIT: Just realized how old this question was. Well maybe this will still be of help to someone.....
We run IIS with Approx 5 different web sites. These websites each have their own root directory. We don't typically access things from the other websites, but if we were to do this I would think we would setup another directory on the server for those files to live in. This is assuming that the files you are trying to access are static files.
To Clarify...
C:\inetpub\WebSite1Root
C:\inetpub\WebSite2Root
C:\inetpub\WebSite3Root
Then place the static files in
C:\StaticFiles
So to access those static files Website1 (or 2 or 3) would simply look in that shared directory.
I'm not sure if this helps but I would be happy to answer questions if you have any.

Setup IIS 6 to only server static files from virtual directories

We're having the same setup and receiving the same problem as:
IIS 6 with wildcard mapping and UNC virtual directory problem
Setup
Server 2003 32bit, IIS 6
ASP.NET wild card mapping
A virtual directory mapped to an UNC share serving static images for a CMS in a load balancing environment
My question if it's possible to turn off asp.net from virtual and only serve static files e.g. images in the virtual directory, to avoid the problem with too many open connections?
If it's not possible I'll guess I have to implement a solution like Version control of uploaded images to file system to server the files from a local disc.
I found a possible solution at http://blog.stevensanderson.com/2008/07/07/overriding-iis6-wildcard-maps-on-individual-directories/ that removes the wild card mapping and makes it possible to turn of execution of asp.net files.
There is not a way to remove .NET from a subdirectory as it is part of an application at this point (your root directory). However, this method works just fine for keeping .NET from processing your static content.
From your site that you linked:
Alternative
If you don’t like to use adsutil.vbs, you can achieve the same by exploiting what appears to be a bug in IIS Manager. Turn your subdirectory into an application (from its Directory tab, click “Create”). Then edit its script mappings to remove aspnet_isapi.dll. Then go back and “Remove” the application you just created. The metabase’s new ScriptMaps value will be retained, even though the option has now disappeared from the GUI.

Resources