How to add full permission to network service through C# - c#

I'm trying to give Network service full access to one folder that is already existing. Is it possible to get it done through code?

Related

Want to read/write file on network from my IIS but access denied

I want to copy one file on the network drive ex. 192.168.0.32/ODfolder
I have hosted C# API on my IIS but when I call API they give me the error "Access Denied"
but when i debug on localhost it will run fine without error and copy the file on the network drive too.
Regards
Rajat Khandelwal
First check whether that network drive is accessible from the machine where you have hosted your application, if yes then give write access on that folder to everyone or the user under which your application pool is running which is hosting your C# API.
Hope this helps. Happy coding...
Check which user you are connecting using .Local IIS uses IIS_USERS. change the user or add permissions to user connecting to the file.

Is there a way to map a path from an external server?

Well, I've been working on my server with a method like the following:    
System.Web.HttpContext.Current.Server.MapPath("/path/something");
... and it's been working so far. Nevertheless, now I've encountered an issue. The thing is, I need to write a file that's located on an external server. Is there a method in C# to do this?
Server.mappath is designed to convert web based paths to local paths based on the location of the webroot, and is not strictly speaking relevant when trying to access external resources.
The only exception being when a remote file location is used as part of a websites file system. E.G. If your website has a folder in it called "/remotefiles/", and within IIS you have mapped this folder to a remote network path. MapPath would work as normal and you will retrieve a full UNC path.
If the server you want to access is on the same network as your web server but not referenced as part of your webroot, then you should look at directly referencing the location in question using a full UNC path. E.G. "\\ExternalServer\CDrive\SomeStuff\".
If the server is remotely accessed over a wider network, then you will need to look into another form of access.

C# Internal Server Error

I wrote a C# WCF server and I am trying to get it up in IIS but everything I try to go to my endpoint I get this error:
I checked the Permissions on the site and I have Authenticated Users others:
so I am not sure what to do now...
I imagine that the root of the problem is that you are trying to create an application on the server that points to files on your own computer using a Remote Desktop Connection drive share. The \\?\UNC\tsclient\C\... path is a dead giveaway.
This is a definite no. You cannot run a web service this way. The tsclient path is specific to your individual connection and will not work from any other context. Any other user account - including the service account that the IIS instance is running from - will not be able to access those files.
To resolve this issue you need to copy the files from your machine to a location on the server and recreate the IIS application entry, referencing the location on the server. You might still need to monkey with the security on the server-local folder.

Get data from Access database present on a different server

I need to connect to an access database file from my web application. The access database file is present on a different server. Is there any way of connecting to the access database file? Is it possible? I tried searching but could not found something to start with. I can connect to something present in the server where my web application is located. I need an approach.
You need a file share to the remote server. You can pass a full UNC name in the access connection string, sucn as:
Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source="\\server\share\Filename.accdb";Mode=Share Deny None
You will need to have the appropriate NTFS and Share permissions on the file. (Read/write)

using windows service can we copy files from one computer to another computer C#.net?

I have one service that will create a text file to local machine and then need to copy the same file to another server .
I am using " File.Copy(SourceFilePath, TargetFilePath, true);"
and getting an exception at the target file path "access denied. I am able to copy the files manually to that location ( TargetFilePath) .
any idea , what is going wrong ??
I don't have any network drive mapping with this target location.
Thanks in Advance
This is a classic permissions issue. You need to make sure that the service is running in the context of a user with the ability to copy files. Since you need to copy files around, I would suggest using a user that is in the Backup Operators group, although you might want something more restrictive for your scenario.
Edit: Since you're also copying to another server, your user will need to have rights on that server as well. For that purpose, you might run your service under a domain account (assuming your machines are both in a domain). You can also test by using the Run As... option on a console app with the same code - that way you can debug permissions issues before setting up the service.
The account that the service is running on must have access to the other machine.
From the source machine can you manually copy the files to the Target?
C:>Xcopy \sourcemachine\dir*.txt \TargetMachine\dir\ /Y/K/D/C
That should help you narrow it down if the problem is related to code or permissions.
If you're not running on a domain, your code can impersonate a user on the other machine that does have rights.

Categories