System.Unauthorized 异常

System.Unauthorized Exception

*

Exception =System.Net.WebException: Access to the path 'c:\windows\system32\inetsrv\Dialer' is denied. ---> System.UnauthorizedAccessException: Access to the path 'c:\windows\system32\inetsrv\Dialer' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing) at System.Net.FileWebRequest.GetRequestStreamCallback(Object state)
--- End of inner exception stack trace --- at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest& request) at System.Net.WebClient.UploadString(Uri address, String method, String data)

*

发生异常的代码

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

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

好吧,问题很简单。该代码试图将 Restful post 生成为空白 Uri。由于 Uri 是空白的,webclient 试图解析对 inetpub 中文件(与服务同名)的调用。

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