Access to the path is denied, when writing to a shared folder - asp.net

I am using Asp.net and from my code I am trying to write files to a shared folder on another PC in the same domain.
I am getting an exception.
UnauthorisedAccessException. Access to the path 'sharedfoldername' is denied.
I gave full access permission to everyone on the specified folder with no luck.

I should probably, write this in comment but I don't have enough rep yet, I will update my answer as you answer my questions.
Do you access the shared folder from the server/PC where the asp.net application is hosted ? You can create a file with Windows Explorer ?
Does the code is hosted on IIS ?

Related

ASP.NET Access to the path denied, on Web Server

I am having a problem, that is when I deployed my asp.net 4.0 application on my web server i am unable to write to App_Data folder. Actually it has an xml file which I am trying to write some information into. I am getting the following error.
Access to the path 'C:\HostingSpaces\hosterind\mydomain.com\wwwroot\App_Data\ErrorLog.xml' is denied.
I tried searching every corner for a possible solution before posting on stackoverflow but i am unable to fix this. Searching similar questions on internet (stackoverflow too) i concluded that i need to handle it through IIS as everywhere it was quoted on internet to grant permission to App_Data folder through IIS Manager. As accessing IIS Manager of your web hosting server is impossible, i supposed people are referring to my local IIS server. So, i copied my project which i was developing in visual studio from location: C:\Users\DanComputer\Documents\Visual Studio 2010\WebSites\MyWebProject and pasted into C:\inetpub\wwwroot. Then i located my project in IIS Manager by selecting DefaultAppPool as application pool. I changed my App_Data folder permission to allow full control for IIS_IUSRS(DanComputer\IISUSRS). Then i copied my App_Data folder to my web hosting space using ftp software but it didn't solve my problem. I tried many thing even changing permission to allow full control for everyone but it did't work and i am still getting the same error. Any help please?
You need to know what is the identity of the Application Pool of your app. You can get this information from IIS or console. It is possible that your hosing company may have a control panel that can give you that information.
Then you need to give permissions to the account in the app pool identity the names will be the same or at least be very similar to what you saw in IIS:
So using my examples above I will have to give permissions to Local Service or Network Service to read/write my app_data folder.

ASP.NET Access to path '\\xxxx' is denied

I know this has come up in other questions, but none seem as simple:
I have a UNC share on another machine, with security set to Full Control for Everyone. If I log into my web server, I can access this share.
However when I try to access it using Directory.GetFiles(path) in the ASP.NET code, it returns an Access to the path \\xxxx is denied. error.
Also oddly, when I run the same website from my local visual studio web server, but pointing at the same path, the directory can be accessed fine.
What am i missing here?!
Add IUSR, IIS_IUSRS as suggested by Carlos487 and Network Service as well with full control on the directory that you are trying to access with your application. Hope this helps.

Access to the path 'C:\Sites\content\ServerIpAddress.txt' is denied

I create a web site that in Default web page of it i try to access to ServerIpAddress.txt file that is on server . now when i run my project on local host it work correctly , but when I upload it on Server(free host) i face with
error. can some one help me ?
You most likely do not have permissions access files on the shared server due to security issues. Consider moving data from that file to web.config app key.
or access the file as a relative path to your site. The remote sever will most likely not have the same folder structure as your local machine.
The account that is being used for the worker process of the web site has no (write)access to the file.
Configure the file (or folder) so that the ASP.NET process has access.
Another thing to look at is whether or not the path as stated in the code is the actual path on the server.
give full permission to ServerIpAddress.txt file. it will work.
Right click on content folder. Click Properties. Then from General tab uncheck the Read-only checkbox.
Then go to Security tab and Allow Write permission for your ASP.NET process.
Are you using a database? In that case how did you set up permissions for app_data folder? You have to set permissions in the same way.
If you are not able to do that, try moving the file inside of app_data folder and then check.
Right click on .txt file and select security and add network service .restart iis and try.It will work.

Folder accessing error in ASP.NET

I am working on a asp.net website which is created by someone else.
Some files are exist in root folder and some are exist in one sub folder.
I can access all files from root folder in the browser, however when try to access the pages from sub folder is shows following error
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
I unable to point out the issue. I checked the web.config file, but didnt get anything related to that folder. I know it is difficult to find the exact issue in my case, but I would appreciate if anyone can give me possible reasons or clues so that i can try.
Thanks in Advance.
EDIT
There is a sub folder web.config with the following content
However, even if I login with "administrator" it fails.
I got the issue, actually previously it was Forms authentication which I commented out.
Is there a web.config file in the sub-folder? These can apply local restrictions.
Other questions that it would be good to know the answer to:
What authentication scheme (forms, windows etc) are you using?
What sort of content are you trying to access (static content or aspx)
what version of IIS are you using?
This sounds like an ACL problem to me. More information, as Xhalent asks, would be useful. Does the user that IIS is using have access to all of the files on the file system?

when I run my asp.net website and I try create file I have an error 'Access denied'

my website does not create files and I set asp.net to write to directory.
The account under which the website runs needs to have permissions to write files to the directory in which you want to write the files.
it could be two things. this access denied error, is it a 403: Access Denied error? If so your IIS setup isn't configured for anonymous users. If its not it could be the IIS user the site is running as doesn't have permissions to access the site's folder.
Double check these two things, if it's neither we can look at what else is happening. Things I try is can I server a static file, or is it just ASP.NET etc
Write access isn't enough to create files. Try giving full control to the ASP.Net user (Network Service ny default) to the temporary files folder you are trying to write to.

Resources