I have written a c# application using LogParser to read IIS Log files.application works fine in my development machine but on server i get the following error.
Access to the path 'C:\inetpub\logs\LogFiles\W3SVC1\' is denied
how can i correct it?
EDIT
I tried to add Relevant permissions to intpub folder but i can not add a new user(ISUSR,NETWORK SERVICES or ASPNET)
because it doesn't show the add button only shows Edit.plz see image
Clicking the Edit button and confirming the subsequent UAC prompt brings up a dialog that allows you add or edit users and groups and their permissions.
Related
Is it possible for a windows service/web application (c#) to write log entries where its running under a windows domain account that is NOT a local admin?
I have tried both of the following for a NON admin windows domain account:
Writing to the Application log (with a 'Test' source). but this gave me 'Access Denied' error.
Initially setup a new custom log called 'Test' that would have appeared under 'Applications and Service Logs' using a local admin windows user account.
I then tried to write logs to this using a non admin windows user account but still ended up getting 'Access denied' error.
I have seen suggestions where the registry needs to be modified but i really don't want to go down that route as it feels hacky and..well..just not right!
I can get both options above to work when i switch the windows user to a local admin, but i don't want this.
Any suggestions greatly appreciated..
(Apologies in advance if this is duplicate POST)
You need to grant access to the log. See Delegating access to the event logs
Open Registry Editor.
Navigate to the following registry path:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog
You will see that there are keys available for each event log. Select the event log for which you want to delegate access.
Add a new key with the name CustomSD to the event log you selected.
Add a new String value to the CustomSD key. The name of this string is not required, but it represents the access control list for the event log in the Security Descriptor Definition Language (SDDL) syntax. In this procedure this value will be referred to as SDDLACL.
As for the SDDL, see Security Descriptor String Format
edI have C# ASP.NET 4.5 Webform application and use the following code:
if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, message, level);
Since the first line was failing I created
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\IDDISLOG in registry
I get the following exception on WriteEntry Method:
Cannot open log for source 'IDDISLOG'. You may not have write access.
Searched other similar questions but none worked for me.
Here is what I have done so far:
Added "Network service" to the project file folder
Added Network service to and gave it full access.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
Added Nertwork service to and gave it full access.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security
Checked and saw w3wp.exe *32 process runs with User Name ASP.Net v4.0.
So added ASP.Net v4.0 to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
Still, error remains
Your user account may not have sufficient privileges to create an event source, which only administrator accounts can do. If you can log in as an administrator, either run your code again or add a folder here: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\IDDISLOG
That should allow your application to write to the event log with that source. You may need to configure the actual registry entry further to suit your needs.
In IIS (Windows server), you should change de identity used by de app pool, so the new identity has permission to write to the event log.
Select the app pool and advanced settings. then edit and insert a custom account, althoug local system will suffice. If you use a custom account be sure not to use a user whose password is going to expire, because when it happens logging to event log will fail.
I have a problem with starting the Excel Application under a particular user.
I try to schedule this script (C#) through an application X (not Windows Task Scheduler. And this application will always use a service account to run services on the server). If I run the C# script in command prompt under the same user, it runs. Under the application X, which uses the exact same user, to initiate the C# script, it fails to open the Excel application (not sufficient permission?).
This script calls:
app.Workbooks.Open(ExcelFileName,0,false,Type.missing....), yet it gives the following error:
Microsoft Excel cannot access the file "...". There are several possible reasons:
-The file name or path does not exist.
-The file is being used by another program.
-The workbook you are trying to save has the same name as a currently open workbook.
I tried all the methods that I found online to no avail.
Create directory “C:\Windows\SysWOW64\config\systemprofile\Desktop” (for 64 bit Windows) or “C:\Windows\System32\config\systemprofile\Desktop” (for 32 bit Windows). Then Set full control permissions on Desktop directory above (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user “IIS AppPool\DefaultAppPool”)
Changed the DCOM config for the Microsoft Excel application to include this user for Local/Remote Launch and Access
Enabled all macros in Excel and set the Trust Center.
Add the user to have full control on all folders that contain the Excel file.
Under DCOM config, Microsoft Excel Application, if I modify the Identity tab to check on "This User" and enter the username/password to let Excel always run under that user. Then the application runs perfectly. However, other users can't run the excel application on their own with the following error: "Cannot use object linking and embedding". If I check "Use the launching user", then Excel can't be launched. No errors in the logs or events anywhere to check.
Yet, still the same error. I think it's permission but I am not sure where and what to do for this to work.
Now, normally, when I run this excel report, I can double-click on the file and it'd automatically run, save the new parameters into the current file and generate a new excel file (with date attached to the file name). That means there is a change (save) to the original file.
I appreciate all your help!
I found the problem is the layer of security in the server!
Creating the Desktop folder inside the C:\Windows\System32\config\systemprofile and giving the service account permission to access the desktop folder is not enough.
I modified the C:\Windows\System32\config (or C:\windows\SysWOW64\config) folder to allow permission to the service account in security tab.
Then I also had to set up the same permission for the sub folder C:\Windows\System32\config\systemprofile (or C:\windows\SysWOW64\config\systemprofile) for the service account.
This works!
Microsoft Excel cannot access the file in Server 2012 Excel 2016.. checked various solutions online to create folder desktop in C:\Windows\SysWOW64\config\systemprofile\desktop.. didn't work for this but then i added a folder desktop in System32 and that definitely worked.
Since I have 64-bit Excel installed, the proper directory turned out to be the
c:\windows\system32\config\systemprofile\desktop
I ran across another way you can get this error: when you try to save a file with an "illegal" name, such as one with whacks (forward slashes) in it.
For that reason, it would seem reasonable that the err msg would give that as one possible explanation of the problem, but...no!
Specifically, I was trying to save a file named C:\RoboReporter\ABUELITOS\20160524_1327\ABUELITOS - Fill Rate - 4\1\61910B10
The whacks (shown as backwhacks in the copied exception text, but seen as forwardwhacks when hovering over the value when debugging) were the cause of the discombobulation. Once I fixed that by replacing whacks with underscores:
filename = String.Format("{0}\\{1} - Fill Rate - {2}.xlsx", uniqueFolder, _unit, _begDate.ToShortDateString());
filename = filename.Replace("/", "_");
...all went swimmingly.
This question have been asked like million times, but I have tried those solutions and still can't find out why this error is coming up:
Access to the path '\server1\Folder1\Folder2\Folder3\file1.dwg' is denied.
Here is the action which returns the error:
public ActionResult Download(string fileName)
{
fileName = fileName + ".dwg";
string path = Path.Combine(#"\\server1\Folder1\Folder2\Folder3\", fileName);
return File(path, "application/octet-stream", fileName);
}
I have tried to giving permissions to "Folder3" for multiple usernames, for example "SERVER1\NETWORK SERVICE" - Full Control.
Application is running under Default Web Site. Application is running under DefaultAppPool and DefaultAppPool has identity of "NetworkService".
Following code gives identity "NETWORK SERVICE".
WindowsIdentity identity = HttpContext.Request.LogonUserIdentity;
The application was working fine (same download directory) on my own computer, but after deploying this problem showed up.
Server is running Windows 2008 R2 SP1 and IIS 7.5.
Try this:
"Access to the path 'xxxxxx' is denied."
As error says you need to assign permissions to folders
Right Click Folder
Go to Security Tab
Click on Edit
Click on Add
Click on Advanced
Find Now
Give Permission to IIS_IUSRS (Full Control)
Click On OK
Click On OK
Click On Full Control in allow
Click On OK
Again Run the Application
Note: if these steps are not working, then try to give same permission to NETWORK, NETWORK SERVICE users
For my case, I went to the root folder of my project, right clicked on it and opened the properties window and unchecked the Read-only attribute. After clicking OK, all started working.
If anonymous authentication is enabled on your server set read permissions for the IUSR account. To allow access for the application pool identities set read permissions for IIS_USERS group. For UNC-path sure that there are relevant permission for your shared folder (see https://technet.microsoft.com/en-us/library/cc726004(v=ws.11).aspx for details).
Please give the full control permission to your directory. Please do this
-Right click on folder
-Go to security
-From Edit give access to IIS_USERS
Ok so I believe I am doing something very easy here. I have written an ASP.NET web page and it is just trying to write to the local directory.
I am using the following code:
System.IO.File.WriteAllLines("log.txt", messages);
I am throwing the following exception.
Access to the path 'c:\windows\system32\inetsrv\log.txt' is denied.
My ASP.NET application sits in the following directory.
c:\inetpub\wwwroot\sites\mysite\
So I am confused as to why it is trying to write to c:\windows\system32\inetsrv\ directory when I am not supplying that directory itself.
I have tried changing the code to the following but it gives me the same error message with a new directory.
System.IO.File.WriteAllLines("c:\\inetpub\\wwwroot\\sites\mysite\log.txt", messages);
Edit 1
It was hard to accept an answer on this because everyone really helped me out a ton. I accepted tom_yes_tom's answer because he was the first to post his response which was the first half of my problem. The other half of my problem was related to hbrock's solution that Fabio pointed out.
Create the folder "C:\inetpub\wwwroot\sites\mysite\App_Data" and save your data there instead.
System.IO.File.WriteAllLines(Server.MapPath("~/App_Data/log.txt"))
If you absolutely must save it to the mysite directory, be aware of security ramifications of putting a log file there and set directory permissions appropriately. The user that IIS is running under needs to be able to read and write that directory.
Full qualifying path: System.Web.HttpContext.Current.Server
You're receiving "Access to the path 'c:\windows\system32\inetsrv\log.txt' is denied." when you execute System.IO.File.WriteAllLines("log.txt", messages) because c:\windows\system32\inetsrv is the directory where the IIS executable is located (w3wp.exe).
You have to use Server.MapPath so it gives you the physical path of your virtual directory.
Look which user is running your virtual directory's application pool, and give him write permissions on the folder of your virtual directory.
This should help:
To grant read, write, and modify permissions to a specific file
In Windows Explorer, locate and select the required file.
Right-click the file, and then click Properties.
In the Properties dialog box, click the Security tab.
On the Security tab, examine the list of users. If the Network Service account is not listed, add it.
In the Properties dialog box, click the Network Service user name, and in the Permissions for NETWORK SERVICE section, select the Read, Write, and Modify permissions.
Click Apply, and then click OK
information from: http://msdn.microsoft.com/en-us/library/ff647402.aspx#paght000015_fileaccess