IIS Express Access denied - c#

I am trying to create new file in visual studio 2012
fileStream = new FileStream("google_com.txt", FileMode.CreateNew);
But i keep getting this error
Access to the path 'C:\Program Files (x86)\IIS Express\google_com.txt' is denied.
Plz help to fix this poblem.

Solutions:
Put a specific location for google_com.txt file. like C:\google_com.txt. Actually it is not allowing to create the file in default location(inside program files) as it might not have the proper privilege.
If you want to create the file in default location(inside program files) run Visual Studio as Administrator.(R-Click-> Run as Administrator).

Run Visual Studio as Administrator

You can't write to the Program Files folders on Windows Vista or later unless you're running elevated/as an administrator.
You should be writing to the application's App_Data folder if you need to write anywhere. Look into using Server.MapPath().

If this is in a web app, the file will be created in the application's root, which in this case is your iis express directory. Run Visual Studio as Administrator, or change the location of the file by specifying an explicit path.

Official Microsoft response:
Issue occurs because of missing permissions on a local resource that
the ASP.NET application tries to access If you are unable to get a
clear description of the problem because of a custom error message,
run FileMon and reproduce the problem. Stop and save the capture as
FileMon.xls and open the file in Microsoft Excel. On the Data menu,
click Filter, and then click AutoFilter to use the filtering
capabilities of Excel. Now select the drop-down list in column F and
look for "ACCESS DENIED" errors.
A sample FileMon output is shown below. 10381 1:01:11 PM w3wp.exe:2320
OPEN C:\winnt\microsoft.net\framework\v1.1.4322\Temporary ASP.NET
Files\sessiontest\8832e585\275ec327\global.asax.xml ACCESS DENIED NT
AUTHORITY\NETWORK SERVICE As you can see from the filtered results,
we have narrowed down the cause of the problem. FileMon shows that the
NT AUTHORITY\NETWORK SERVICE account is missing NTFS permissions on
the C:\Winnt\Microsoft.net\Framework\v1.1.4322\Temporary ASP.NET Files
folder. This should be straight forward to fix. For more information
about using FileMon to troubleshoot ASP.NET, click the following
article number to view the article in the Microsoft Knowledge Base
https://support.microsoft.com/es-ve/help/910449/troubleshooting-common-permissions-and-security-related-issues-in-asp

Try this:
Server.MapPath("~/ FolderName / google_com.txt ")

Related

C# exe not working once installed to program files folder via Wix

I have a C# winforms application which will not work once installed to the C:/ProgramFiles folder. I use an MSI created with Wix to install. When either double clicking the exe or right clicking and running as admin this window pops up and then nothing happens:
Application Error Message:
The application works in Visual Studio and when accessed via the bin/Debug folder of my VS project (the exe in the Debug folder is the one I am using for the Wix install).
After the MSI installs, if I copy the exe out of
C:/ProgramFiles to one of my user folders (ex: C:/Users/User/Desktop) the exe works.
I am guessing this is some sort of UAC/permissions issue but I cannot find any documentation to confirm that theory. Any direction would be much appreciated.
EDIT:
Looking at the error log it is denying me access to my config file. Here is the error text:
Access to the path 'C:\Users\*username*\AppData\Roaming\Leer Copy\leerConfig.xml' is denied.
EDIT II:
This problem is getting more confusing (and frustrating). It will allow me to write to the AppData folder but not read from it (shouldn't it technically behave the other way around?)... Would really appreciate some help. I am reading the contents of my XML file via XDocument.
Originally had hid the config file so people do not mess with it/accidentally delete it. Making the file not hidden fixed the access denial and everything works how it should now.

Unauthorized Access Exception writing file from .exe

My WPF application writes an XML file to a folder within the CommonApplicationData folder on a Windows 7/64 machine. This works fine from Visual Studio 2010. When running from the .EXE file, I get a System.UnauthorizedAccessException when writing the file.
Is this a problem with my initial setup of the folder? Or is this related to the permissions of the executable file itself? Not quite sure how to handle this one??
Paul
I think that it is a problem with permissions to the folder.
Probably Visual Studio runs your application as an administrator and the .EXE file is executed as a normal user.
Perhaps you want to re-evaluate storing that data (XML) in that location all the time. Limited users won't be able to write to it. Sure, you can force admin privs but your users may not always have that option (and it's kinda a hack anyway).
The question below seems to outline a work-around depending on the user's priv level.
writing files to Common Application Data folder denied
Right click on the *.exe file and "Run as administrator".

Access to the path 'C:\xxx\yyy\zzz\abcd_20120309.pdf' is denied

I have an ASP.Net website and a C# console application (both developed in VS2010). Both upload files to our web server (Windows Server 2003/IIS 6.0). Users logging in to the website can then view and download these files.
This works fine in website. But when I try to download files uploaded by the console application, I get the error:
UnauthorizedAccessException
Access to the path 'C:\xxx\yyy\zzz\abcd_20120309.pdf' is denied.
I have already manually provided "Full Control" to NETWORK SERVICE account for that folder.
Why is Asp.Net code unable to access a folder created by the console application?
Any idea?
Thanks!
You need to provide access to the folder for IIS_IUSRS (or something along this line).
AKA you need access for IIS.
Including access to everyone, doesnt include this user. So it must be done directly.
Network service will not suffice.
If IIS_IUSRS doesnt appear in the list, search for it.
Don't know if it matters in this case but one thing I have seen in the past is:
The application first saves the file in a temporary folder and then moves it to the target folder.
Sometimes, don't know the exact rules, the file access right follows the file in the move. i.e. the file ends up with the access rights for the temporary folder even in target folder.
Check the access rights on the file and see if it differs from the target folder.

Changing virtual directories in IIS 7

I just got a new pc running Windows 7. My old box had XP. I copied all of my files to a newtwork directory, then copied them down to the new pc.
I have an application built in Visual Studio 2003 that I'm trying to do maintenance on. When I try to open it I get the following error message:
Unable to open Web project 'EDIWebFormsUI_1'. The file path 'c:\inetpub\wwwroot\EDIWebFormsUI_1' does not correspond to the URL 'http://Localhost:/EDIWebFormsUI_1'. The two need to map to the same server location.
I found an article on Microsoft TechNet telling how to change the mapping of a virtual directory at http://technet.microsoft.com/en-us/library/cc754640(WS.10).aspx.
However, it says "5. In the Actions panel, click Basic Settings."
I don't have a Basic Settings option in my Actions panel.
I also tried appcmd from the command line, but I get the message "appcmd is not recognized as an internal or external command."
Do you know of another way to change the virtual directory mapping for my application?
VS2003 is a bit old, but there should be a plaintext file somewhere in the project directory that points to the virtual directory location hosting the web project.
To use Appcmd, you may need to change your directory before you try to run the command. At the command prompt, type cd %windir%\system32\inetsrv then run your command. That should solve the issue.

Self-Updating .NET client application which needs to write in the Program File folder

Similar to: Request Windows Vista UAC elevation if path is protected?
I have a .NET Client Application installed in c:\Program Files (Windows Vista). This application should update itself, but it doesn't because of permission issues. The auto-updater should simply replace a couple of assemblies, but they are all located under c:\Program File and the application throws the following exception:
System.UnauthorizedAccessException:
Access to the path 'C:\Program
Files...' is denied.
I have no control on where the application could be installed and the permission. Is there any workaround for this? Is it possible to request the Administrator rights for a couple of seconds? Is it possible to pop a UAC window? I am pretty sure that there a workaround... Otherwise, how Firefox would be able to update itself?
Thanks in advance for the help and ideas!
Could you use a Click Once deployment method? We use this for an internal application and users have no problems with permissions when we publish a new version. They are prompted to install the update when they launch the app (if a new version exists) and it installs without a hitch.
You can't elevate a process's permissions halfway through, but you can start up another separate process with higher permissions that can do the work for you.
Get your main application to put all the files / installation details into a low-permission temporary location. When you're ready, start up a smaller application whose only job is to copy over those files to the Program Files directory (and maybe restart your main application with the new updates). Mark that application as requiring the needed permission to copy to the Program Files directory or write to the registry (or whatever else is needed).

Categories