Write a file from webservices

I have a web service using .net C # and I want to write to a text file on the server, but I cannot get this to work. I believe this is a resolution problem.

In particular, I think the problem is what I use System.IO.Directory.GetCurrentDirectory().

Is there a better alternative?

+3
source share
5 answers

Try granting the ASP.NET user (or regardless of the IIS account) write permissions to the folder you are trying to write.

If this is a network share, try starting IIS as a domain user who can write to the share.

Remember the principle of granting minimal permission (do not use access to the administrative level).

+9
source

, , - "C:\Windows\System32 \" - . UnauthorizedAccessException. "" - -, , .

, .

System.Web , :

strFileDestination = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + strFileName;

IIS.

+3

Windows 2003 ASP.NET DefaultAppPool , "Network Service", " " . , , "Network Service", .

Windows 2000, '<MACHINENAME>\ASPNET' .

, .

, , ( , ASP.NET 2.0), machine.config(C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG), , :

<identity impersonate="true"/>

web.config.

, , , , -, FileIOPermission $AppDir $, , NTFS.

, StingyJack , - .

NTFS, , , .

,

+2

, System.IO.Directory.GetCurrentDirectory(), Server.MapPath. Server.MapPath -, , , , "C:\Files\file.txt". , , , IIS_WPG ASPNET ( ).

+2

You should be able to write files from web services. Most likely, it is a matter of permission or trust. If you have limited trust (i.e., medium trust), make sure you write the patch in or below the root directory. If you are already doing this or are in full check of the verification environment, make sure that the directory has permissions for the IIS workflow to write it.

0
source

Source: https://habr.com/ru/post/1698674/


All Articles