相关疑难解决方法(0)

IIS/ASP.NET的所有用户帐户是什么?它们有何不同?

在安装了ASP.NET 4.0的Windows Server 2008下,有大量相关的用户帐户,我无法理解哪一个是哪个,它们如何区别,哪一个真的是我的应用运行的那个.这是一个清单:

  • IIS_IUSRS
  • IUSR
  • 默认应用
  • ASP.NET v4.0
  • NETWORK_SERVICE
  • 本地服务.

什么是什么?

asp.net security iis user-accounts

271
推荐指数
1
解决办法
17万
查看次数

如何配置我的ASP.NET目录以允许编写日志文件?

好的,我相信我在这里做的很容易.我编写了一个ASP.NET网页,它只是试图写入本地目录.

我使用以下代码:

System.IO.File.WriteAllLines("log.txt", messages);
Run Code Online (Sandbox Code Playgroud)

我抛出以下异常.

Access to the path 'c:\windows\system32\inetsrv\log.txt' is denied.
Run Code Online (Sandbox Code Playgroud)

我的ASP.NET应用程序位于以下目录中.

c:\inetpub\wwwroot\sites\mysite\
Run Code Online (Sandbox Code Playgroud)

所以当我不提供该目录时,我很困惑为什么它试图写入c:\ windows\system32\inetsrv \目录.

我已经尝试将代码更改为以下,但它给了我与新目录相同的错误消息.

System.IO.File.WriteAllLines("c:\\inetpub\\wwwroot\\sites\mysite\log.txt", messages);
Run Code Online (Sandbox Code Playgroud)

编辑1

很难接受这方面的答案,因为每个人都真的帮了我一大堆.我接受了tom_yes_tom的答案,因为他是第一个发布他的回答的人,这是我问题的前半部分.我的另一半问题与法布里奥指出的hbrock解决方案有关.

c# asp.net iis

7
推荐指数
1
解决办法
1万
查看次数

File.Copy中的C#UnauthorizedAccessException

我正在刷我的C#所以我决定编写一个程序,我可以用来轻松导入我拍摄的照片.一点点背景......我用JPEG和RAW拍摄照片,然后浏览并选择JPEG,因为它们更小,更容易处理/预览.然后我只导入那些在后期制作中值得搞乱的RAW文件.

我想写一个简单的程序来复制一个目录中的RAW文件,该目录与我在另一个目录中筛选的JPEG相匹配.

这是代码:

static void Main(string[] args)
    {
        Console.WriteLine("Enter the JPEG Origin Directory: "); 
        string originDirectory = @"C:\Users\Greg\Pictures\Summer 2013\Back Bay\testJPEG";

        Console.WriteLine("Enter the RAW Origin Directory: ");
        string copyDirectory = @"C:\Users\Greg\Pictures\Summer 2013\Back Bay\testRAW";

        Console.WriteLine("Enter the RAW Import Directory: ");
        string rawCopyDirectory = @"C:\Users\Greg\Pictures\Summer 2013\Back Bay\testRAWImport"; 

        char[] delimiterChars = { '_', '.' };

        List<string> filesToCopy = new List<string>();
        List<string> CopiedFiles = new List<string>(); 

        foreach (var filePath in Directory.GetFiles(originDirectory))
        {
            Console.WriteLine("Filepath: '{0}'", filePath);
            string[] words = filePath.Split(delimiterChars);

            filesToCopy.Add(words[1]); 
        }

        filesToCopy.ForEach(Console.WriteLine);

        foreach (var copyFilePath …
Run Code Online (Sandbox Code Playgroud)

c#

7
推荐指数
2
解决办法
2万
查看次数

如何将文件从特定文件夹复制到C#中的共享文件夹?

我正在尝试将现有文件从特定文件夹复制到共享文件夹.所以这是代码:

if (!System.IO.File.Exists(fullPath))
            {
                using (WindowsIdentity.GetCurrent().Impersonate())
                {

                    try
                    {

                        image.Save(fullPath);

                        System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(originalDocumentFolderPath);
                        FileSystemAccessRule accRule = new FileSystemAccessRule(originalDocumentFolderPath, FileSystemRights.FullControl, AccessControlType.Allow);
                        sec.AddAccessRule(accRule);
                        string sharedFolderPath = "\\" + Path.Combine(Environment.MachineName, "Users");
                        sharedFolderPath = Path.Combine(sharedFolderPath, username);
                        sharedFolderPath = Path.Combine(sharedFolderPath, "Desktop");
                        sharedFolderPath = Path.Combine(sharedFolderPath, "SharedFolder");
                        System.IO.File.Copy(originalDocumentFolderPath, sharedFolderPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

            }
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

System.Security.Principal.IdentityNotMappedException:'无法翻译部分或全部身份引用.'

在这一行:

 sec.AddAccessRule(accRule);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?如果您需要更多数据,请告诉我们......

编辑:

此外,最终目标是这实际上应该将文件保存到LAN网络中特定计算机上的共享文件夹中,但我目前正在尝试将其保存在程序运行的同一台计算机上的共享文件夹中.

编辑2:

所以我尝试了@PaulKaram的建议,但我仍然得到下一个错误:

在此输入图像描述

从图片中,可以看到文档中我首先保存图像的文件夹.这没有问题.当我尝试将其复制到桌面上的特定共享文件夹时,出现在文档中已创建的文件夹上面的错误(访问被拒绝).

c# windows-identity winforms

5
推荐指数
1
解决办法
324
查看次数

创建文件时System.UnauthorizedAccessException

我试图编写代码,以便我可以记录错误消息.我试图用日期命名文件,并希望每天创建一个新的日志文件.经过一番浏览后,我带来了以下代码......

class ErrorLog
{
    public void WriteErrorToFile(string error)
    {
        //http://msdn.microsoft.com/en-us/library/aa326721.aspx refer for more info
        string fileName = DateTime.Now.ToString("dd-MM-yy", DateTimeFormatInfo.InvariantInfo);

        //@ symbol helps to ignore that escape sequence thing
        string filePath = @"c:\users\MyName\mydocuments\visual studio 2012\projects\training\" +
                            @"discussionboard\ErrorLog\" + fileName + ".txt";

        if (File.Exists(filePath))
        {
           // File.SetAttributes(filePath, FileAttributes.Normal);
            File.WriteAllText(filePath, error);
        }
        else
        {
            Directory.CreateDirectory(filePath);
           // File.SetAttributes(filePath, FileAttributes.Normal)
           //Throws unauthorized access exception
            RemoveReadOnlyAccess(filePath);
            File.WriteAllText(filePath, error);
        }
    }

    public static void RemoveReadOnlyAccess(string pathToFile)
    {
        FileInfo myFileInfo = new FileInfo(pathToFile);
        myFileInfo.IsReadOnly = false;
        myFileInfo.Refresh();
    } …
Run Code Online (Sandbox Code Playgroud)

c# exception

4
推荐指数
1
解决办法
2万
查看次数

.Net Core 应用程序无法将文件写入任何 OSX 文件夹

我正在 OSX 中构建一个 .net core 2.0 应用程序,它是一个 WebAPI 应用程序,当 API 端点被命中时,它会创建一个带有虚拟数据的 .xlsx。当我尝试运行它(dotnet run)时,我得到

System.UnauthorizedAccessException: Access to the path '/Users/myuser/projects/myproject' is denied. ---> System.IO.IOException: Permission denied
Run Code Online (Sandbox Code Playgroud)

我尝试将它作为 sudo 运行并更改它正在写入的文件夹,但都没有帮助

// GET api/values/5
    [HttpGet("{id}")]
    public string Get(int id)
    {
        CreatePackage("./");
        return "value";
    }

    public void CreatePackage(string filePath)
    {
        using (SpreadsheetDocument package = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook))
        {
            CreateParts(package);
        }
    }

    private void CreateParts(SpreadsheetDocument document)
    {
        WorkbookPart workbookPart = document.AddWorkbookPart();
        GenerateWorkbookPartContent(workbookPart);

        WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>("rId1");
        GenerateWorksheetPartContent(worksheetPart);
    }

    private void GenerateWorkbookPartContent(WorkbookPart workbookPart)
    {
        Workbook workbook = …
Run Code Online (Sandbox Code Playgroud)

.net c# macos asp.net-core

4
推荐指数
1
解决办法
1926
查看次数

访问路径被拒绝(Xamarin/Android)

我正在运行 Windows 10、Visual Studio 2015 和 Xamarin。我对 Xamarin 比较陌生(只是为了设置地面)。我最近更新后遇到了一个问题。我的应用程序在更新之前正在运行。我的所有文件都是只读的,更新之前我没有遇到任何问题。除此之外,我还重建了该项目,并为该项目进行了“清理和重建”。我已经用我拥有的多个应用程序尝试过它,其他应用程序没有这个问题。我在下面收到以下错误的问题。

06-26 13:51:55.108 I/MonoDroid( 6985): UNHANDLED EXCEPTION:
06-26 13:51:55.142 I/MonoDroid( 6985): System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/defaultDirectory/users.ini" is denied.
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001f1] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin windows-10 visual-studio-2015

2
推荐指数
1
解决办法
1万
查看次数

无法递归删除用户文件夹中的文件夹。mscorlib.dll中发生“ System.UnauthorizedAccessException”

我试图删除包含用户“用户名”及其内容位于C:\ Users \ User的每个文件夹,如下所示:

    foreach (var subdir in directory.GetDirectories().Where(subdir => subdir.Name.ToLower().Contains(Environment.UserName))) {
        try {
            Directory.Delete(subdir.FullName, true);
        } catch (Exception exception) {
            Console.Write("Deleting " + subdir.FullName + " caused exception: \n" + exception);
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试运行Windows Form二进制文件时,命中前几个文件时,mscorlib.dll错误中出现了'System.UnauthorizedAccessException'错误。事情就是这样,我以管理员身份运行它,我可以在资源管理器中删除这些文件而不会出现问题(甚至没有UAC提示),并且没有进程锁定/使用这些文件。

这是怎么回事?

.net c# windows file winforms

1
推荐指数
1
解决办法
790
查看次数