.NET MVC Websites - shared folders between websites - c#

I have a production website that sits on two servers that used local label files to drive their page labels (request going round robin between the two).
Users need the ability to upload new labels files, but once uploaded on one I need it also updated on the second website - this needs to be immediate. I was trying to use a shared folder on one of the servers, but even if I give it everyone full access i get the error "Exception message: Unable to find label folder at \\MACHINENAME\LabelFiles" when reading from the other server, I've also tried giving full permissions to "IIS AppPool\DefaultAppPool", but get the same issue.
I'm using IIS 7.5 on Windows Server 2008 R2
Question-
Is there a way to share a folder between the two sites?
Is there a better alternative solution?
Thanks

Both the websites should have a virtual folder pointing to the same physical folder, where the users can upload files.
Make sure also that the Anonymous access is disabled

One approach is to map the folder as a drive on each of the production machines, it should then be as simple as refereing to that particular drive letter.
This can be done by navigating to the folder in windows explorer, then clicking Map Network Drive.
I cannot guarantee this will work, buut it might be worth a go.

The IIS AppPool\DefaultAppPool user is a special account that is only local to the machine where it is being used. You cannot access network file shares with that account. You will either need to use the 'Network Service' account or a domain account as the app pool user.
Also, since you are load balancing this site between two servers, you might want to consider using some type of SAN or NAS storage that is shared between the two servers. Otherwise, you will need to come up with some kind of process to synchronize the file share on both servers.

Related

Accessing a VFS shared network Drive through ASP Website and Viewing the files inside, Possible IIS fault

I have an ASP.NET website, that has to access a shared network drive. The shared network drive is on an EMC path or ECS. The management module for the shared drives is EMC made, accessible through a browser, so I am assuming.
In the web.config, I have the drive names as Z:, R: etc..
I am able to mount them on the cmd line with the following line. Otherwise, there is no windows access to VFS folder through the address bar or a browser.
mount -o xx.xx.xx.xx://vfs/folder_I_need_to_Access_to. Z:
I have modified the program's code, mounted the drives and am able to access the files while debugging the code, in the web browser. However, once I publish my code to the IIS server, the code does not seem to access the files and view them, even though the drive is mounted as a network drive and accessible through windows explorer. I have checked permissions on both EMC manager, Windows and IIS.
Some of my distant colleagues have said their teams ran into such issues and fixed them, however they have no idea what to do since they do not usually have logs or bugfixing documents, so I am assuming, mine is not an isolated case.
If you need more info on the subject, feel free to ask, I have scoured the internet and applied every solution by the way. Like NekoDrive, network utility libraries, among other questions on StackOverflow.
EDIT : adding the network folders to IIS as virtual directories does not work as well, however, I am able to access the files and folders through IIS manager content view, so I assume IIS is able to scan the directories and has appropriate permissions to the folders. Also, the user running the website is a domain admin and able to access directories as well.
tldr; The program deployed on IIS cant access the network shared folders under a vfs directory, while its owner and the debugged code on localhost is able to.
I have finally solved the issue.
In case anyone else stumbles here,
Since mounting the drives was impossible, I have modified the web.config to have the IP address instead of the mounted drive's letter in IIS manager, Configuration Editor.
So instead of Z:\ , K:\ or F:\
now it says;
\\XX.XX.XX.XX\VFS\SHARED_FOLDER
and the download link is generated as follows, take note of the backslash and slashes
\\XX.XX.XX.XX\VFS\SHARED_FOLDER\file_path/file_path/file_name
Because it would clearly show the IP of the machine while the download link is hovered on, I am encrypting and decrypting the link variable during runtime.

Shares files folder between two web servers

I am implementing a C# (.NET) application in which user can upload files and images due to huge size (more than 80 gb) we are storing these files on file system now I am preparing a another web server which need to access those files.
My question is How can I access files from IIS from another server, both servers are on same network sharing folder does not solve problem for me
I read about using virtual folder but I have concern will it put extra load on IIS for handling user requests ?
Thanks in advance
If it's on the same network, just access it via a network share. Using a virtual directory can be helpful, if for example you'd like to change the network location without having to change any code that references the location. The virtual directory itself won't put any extra strain on the IIS.
Local network speed will be your only bottleneck compared to files stored on the same machine as the IIS as far as I can tell, since you will be transferring the files first on your local network from one machine to the IIS machine, and then to the end user.

Issue with permissions when executing a File.Exists through asp.net site

I've got a script that checks if a file exists. The path is a network share that exists on the server..
I.e. the directory is D:\Mainfolder\Subfolder\file.txt
the network share is \Server\Subfolder\file.txt
The file exists, however from my asp.net site, it says that it doesn't.. I assume that this is a permissions issue since it works if the file is in a different folder.
I've added a bunch of accounts to the permissions of both the share and the folder, but nothing is working..
Is there a way to display which user the File.Exists is being executed as?
Thanks
The user that is accessing the files is the user configured on the application pool of the ASP.NET site or virtual directory. By default, this user will not have access to many local folders/files, let a lone a network share. You have two options:
Change the user configured for the application pool to a user that has access to not only the local files necessary to run the site, but also has access to the network share.
Configure impersonation in the Web.config. See this other SO question here which has a snippet of configuration from Web.config for impersonation.
Some links:
IIS6 Application Pool Identities
IIS7 Application Pool Identities
Starting with Vista a Windows Service is not allowed to access "Desktop things" - one of these being a mounted drive letter aka network share...
You could mess around with the permissions etc. but even if you get it to work this is not supported...
What is the exact goal ? Perhaps there is some other way...
It's probably going to be the user that your application pool is running under. You can see the list of application pools in IIS manager.
However, you can also use Process Monitor to see what users are trying to access the files on your server (including attempts that fail due to insufficient permissions). You can find it at http://technet.microsoft.com/en-us/sysinternals/bb896645. You'll probably need to run this on the remote server where the file actually exists.
Another thing to consider is that while the D:\ drive might be mapped as a network drive when you log in interactively with your account, it probably doesn't exist when the website user is 'logged in'. You'd be better off telling the website to use the UNC path (\server\subfolder...) rather than the D:\ path.
As others have mentioned, your application is probably running under the Application Pool identity. Unless you've changed it explicitly, this account will not show up in your list of accounts to configure.
Getting that sorted out isn't going to help you, though, if you are attempting to access a resource though a mapped drive, as the mapped drive exists only within the scope of the logged-in user.
Think of it this way: you and a colleague share a machine, and you map drive D:\ to \serverA\Shared\Matt, your colleague isn't going to log in and have drive D:\ mapped to your share. She can freely map drive D:\ to \serverX\Secret\Resources.
Start by making sure that you are using a UNC path, then work through the web of permissions issues.

Building, and Publishing, and User-Data (oh my!)

What is the best way to update a "Web-Application" ("re-publish" from dev server to live server) while preserving user-data (such as images, videos, and audio stored in the filesystem) in a VS 2010 build/publish setup?
Additionally, what is the best way to minimize site downtime during these updates?
My backstory:
Usually I "build/publish" the site to a folder on my dev machine, ftp:// into the live server, then drag-and-drop the new "published" files and folders to the live site while making sure not to overwrite any user-generated directories.
Obviously this method comes from my static-html days where it didn't matter. And obviously this is dangerous, flawed, and counter-productive for any Web Application with user-generated data in the FS.
The easiest way is to have a directory that's outside of your code folder where you store the user data. You can even map this folder as a virtual folder in IIS when you need this folder to be available from the internet. Like:
C:\Inetpub
\ProjectWebsite
\ProjectFiles

Redeploying an ASP.NET site in IIS7 without files in use interfering

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.

Categories

Resources