【问题标题】:System.Unauthorized ExceptionSystem.Unauthorized 异常
【发布时间】:2015-08-24 14:58:14
【问题描述】:

*

Exception =System.Net.WebException: 访问路径 'c:\windows\system32\inetsrv\Dialer' 被拒绝。 ---> System.UnauthorizedAccessException:访问路径 'c:\windows\system32\inetsrv\Dialer' 被拒绝。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess 访问、Int32 权限、布尔用户权限、FileShare 共享、Int32 bufferSize,FileOptions 选项,SECURITY_ATTRIBUTES secAttrs,字符串 msgPath, Boolean bFromProxy, Boolean useLongPath) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess 访问、FileShare 共享、Int32 bufferSize、FileOptions 选项、字符串 msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String 路径、FileMode 模式、FileAccess 访问、FileShare 共享)在 System.Net.FileWebStream..ctor(FileWebRequest 请求,字符串路径, FileMode 模式、FileAccess 访问、FileShare 共享)在 System.Net.FileWebRequest.GetRequestStreamCallback(对象状态)
--- 内部异常堆栈跟踪结束 --- 在 System.Net.WebClient.UploadDataInternal(Uri 地址,字符串方法, Byte[] 数据,WebRequest& 请求)在 System.Net.WebClient.UploadString(Uri 地址,String 方法,String 数据)

*

发生异常的代码

using (var writer = new StringWriter())
    {
       JsonSerializer.Create().Serialize(writer, payLoad);
       var result =client.UploadString(commDialerApiUrl,writer.ToString());
       return ((T)JsonConvert.DeserializeObject(result, typeof(T)));
    }

我知道上面的代码并不理想,但是我只需要了解为什么会尝试访问。任何人都可以提供一些见解吗?

【问题讨论】:

  • 好吧,问题的原因是明文!你还能要求什么呢? =)
  • 为什么不检查以确保您可以访问该文件夹,如果更糟以管理员身份运行您的应用程序或右键单击您的 Visual Studio 快捷方式并单击以管理员身份运行,看看是否工作.. 否则设置文件夹权限
  • 如果你的问题是'为什么这段代码甚至试图访问'c:\windows\system32\inetsrv\Dialer' 那么你能确认一下你在 commDialerApiUrl 中有什么吗?
  • Url 属于 WCF REST API。是的,我更想知道为什么要尝试访问。我意识到,如果我授予对该文件夹的访问权限,它将起作用。

标签: c# json.net unauthorizedaccessexcepti stringwriter webclient.uploaddata


【解决方案1】:

好的,问题很简单。该代码试图向空白 Uri 发布一个 Restful 帖子。由于 Uri 是空白的,webclient 试图解析对 inetpub 中文件(与服务同名)的调用。

由于没有这样的文件路径无效,因此出现 i/o 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-11
    • 2021-12-05
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多