I am trying to save an uploaded file:
string SaveLocation = Server.MapPath(#"~\Data");
FileUploadControl.SaveAs(SaveLocation);
I have provided Full control permission for for both solution and target saving folder for the below user accounts:
Network Service
IIS_IUSRS
ASP.NET/machine
IUSR
I have set <identity impersonate="false" /> in web.config.
I tried all the above but still not able to access the path:
ERROR: Access to the path is denied
Let me know what I need to do to access the path.
FileUploadControl.SaveAs requires a full file name, not only the directory as you pass to it.
string SaveLocation = Server.MapPath(#"~\Data\somefile.png");
FileUploadControl.SaveAs(SaveLocation);
Make sure to change the file path every time you upload a file, or the file will be overwritten.
Related
In my project, when user upload a file in the web page which hosted in serverA, the web page should also copy that to serverB. ServerA and serverB is under the same network which admin can access ServerB file from serverA via network drive(//servername/C$/folderpath).
string fileName = "my test.txt";
string sourcePath = #"C:\myFolder";
string targetPath = #"\\vmtest001\C$\myFolder\subFolder";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath)) //error
{
System.IO.Directory.CreateDirectory(targetPath);
}
I have tried to copy that file to ServerB and the error message is
Access to the path '\vmtest001\C$\myFolder\subFolder'is denied.
I see some solutions for that are using a webserivce to move file, could anyone tell me the possibility of that?
Main question: How to copy file between different server?
Add this to your web.config:
<identity impersonate="true" userName="accountname" password="password" />
But this is not recommended.
You can start a service on ServerA, using FileSystemWatcher to monitor the upload files, copy file to serverB in this service。
I am facing issue in my web application which is made in asp.net. I have host the application on IIS server.and I am going to upload excel file to port data in database from application.when i uploading from locally from server itself its working fine but i when i try to uploading using public ip or outside then my application redirect to IIS root folder can any one tell me whats is the issue.
this could be an permission issue on your web.config, file and folder permission or maybe a missing reference to correct folder.
Web.config
What is the authentication ? Do you allow Anonymous access. I understand that you can upload fine if you open the side from localhost from the server itself. Did you try to open the side with public ip from the server itself ?
Application Pool in IIS
Look for the "Identify" configuration and set this to "ApplicationPoolIdentify"
File Permission
Look for the folder and ensure that the "IIS_IUSERS" got write permissions
Code Try to sepecify the correct path using the server.MapPath()
Dim myPath As String = Server.MapPath("foldername") & "\" & "filename.csv"
I'm trying to create a new directory tree on a network path.
The share is located at \\192.168.5.193\FileContext and has Everyone full access permissions.
This piece of code:
DirectoryInfo directoryInfo = Directory.
CreateDirectory(#"\\192.168.5.193\FileContext\FileContext_Root\General\Test");
gives me:
An exception of type 'System.IO.IOException' occurred in mscorlib.dll
but was not handled in user code
Additional information: Logon failure: unknown user name or bad password.
If I try to open the same address with Windows Explorer, it opens up without password requirements.
The CreateDirectory() documentation states it should accept UNC paths:
You can create a directory on a remote computer, on a share that you have write access to. UNC paths are supported; for example, you can specify the following for path: \2009\Archives\December in Visual Basic, and \\2009\Archives\December in C#.
It also states that IOExceptions could came from:
The directory specified by path is a file .
-or-
The network name is not known.
https://msdn.microsoft.com/en-us/library/vstudio/54a0at6s(v=vs.100).aspx
How can I resolve?
Starting from #JamesThorpe comment:
Everyone isn't Everyone
I came to the solution, just by adding the remote computer to the company domain.
With this action, it's not even necessary to add local computer's NETWORK SERVICE to remote folder's permissions.
I want to change web.config file appsetings values which is located in the server. i have given full permission to that folder still unable to access and edit the web.config file
while executing the code its giving error saying - Exception of type 'System.Web.HttpUnhandledException' .unable to access file resides in server
error:
System.UnauthorizedAccessException: Access to the path
'C:\Hosting\chek\demo.checks.in\wwwroot\web.config' is denied.
aspx.cs
string emailid = txtEmailid.Text.Trim();
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
config.AppSettings.Settings.Remove("kumarSunlightitMailid");
config.AppSettings.Settings.Add("kumarSunMailid",emailid);
config.Save();
lblNewEmailid.Text = ConfigurationManager.AppSettings["kumarSunMailid"] + " is ur new mail id";
web.config
<appSettings>
<add key="kumarSunMailid" value="krishna#gmail.com" />
</appSettings>
You are facing this error because you don't give read/write permissions to
user..
check couple of things
check wether web.config is readonly.. if so then uncheck that Option
Right Click on Web.config -> goto properties -> security and check you User does have read/write permissions. if not then give it read/write permissions
If you haven't tried this, try adding the Everyone User to that folder, and give him full access. Next, could try setting the configSource of appsettings so that these are stored in a separate config file:
<appSettings configSource="appSettings.config" />
And then create a new file in the same folder called appSettings.config:
<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
<add key="yourKey" value="yourValue" />
</appSettings>
Try adding the Everyone user with full access to both files too.
Otherwise, I'd create a new solution an see if you can recreate this odd behavior there.
Please give permission to the current user to full access the iis project or solution.
It seems I have a strange issue with security:
I have a website with the following folders:
inetpub\wwwroot
inetpub\wwwroot\readyfordownload
The IIS APPPOOL\Classic user has full access to this 'readyfordownload' folder.
Now I have a console APP that creates a zipfile in the readyfordownload folder. This is done from a c# classlib. Strangely enough, the IIS APPOOL cannot access this file, even though it has full control over the folder. Also, the classlib first creates an xlsx file that is later added to the zip. The APPPOOL user does have access to the xlsx file.
If I run the same function in the C# classlib from a code behind in the website, the same zipfile is created and the IIS APPPOOL user CAN access the file....
Any ideas?
zip is created like this (not the actual code, but it is the same)
http://dotnetzip.codeplex.com/
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("test.xlsx");
zip.Save("MyZipFile.zip");
}
OS is windows 2008 R2 web server
ZIP library is Dotnetzip (Ionic)
Update: I am most interested in why the ZIPfile does not get the rights and the xlsx file does....
Have you tried setting the FileAccessSecurity explicitly? Maybe the files are not inheriting the ACL from the directory.
the apppool user can access the xlsx file because your console creates it directly under readyfordownload folder.
the zip file on the other hand is first created in a temp folder and then copied to your folder. This means that the file permissions are wrongly set on the file.
Make sure IIS_IUSR and DefaultAppPool users have access on your wwwroot.
As scottm suggested change your console code to give permissions to the IUSR and DefaultAppPool users on the zip file. Your code should read like:
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("test.xlsx");
zip.Save("MyZipFile.zip");
var accessControl = File.GetAccessControl("MyZipFile.zip");
var fileSystemAccessRule = new FileSystemAccessRule(
#"BUILTIN\IIS_IUSRS",
FileSystemRights.Read | FileSystemRights.ReadAndExecute,
AccessControlType.Allow);
var fileSystemAccessRule2 = new FileSystemAccessRule(
#"IIS AppPool\DefaultAppPool",
FileSystemRights.Read | FileSystemRights.ReadAndExecute,
AccessControlType.Allow);
accessControl.AddAccessRule(fileSystemAccessRule);
accessControl.AddAccessRule(fileSystemAccessRule2);
File.SetAccessControl(path, accessControl);
}
Check Windows EventLog for related errors. For detailed info use ProcessMonitor, so you can see if there is a problem with permissions.
Configure the security of the folder using “advanced securty setting property page”. (Select properties--> security). Also note that the application pool can impersonate the user so that the application may not be serving the request with the identity of the app pool. By default impersonation may not work. You have to set it explicitly in the web config. E.g. <identity impersonate="true" /> or <identity impersonate="true" userName="domain\user" password="password" />
Sriwantha Sri Aravinda