使用 C# ASP.NET 时“WebClient 请求期间发生异常”

2024-01-29

因此,我为我的程序构建了一个自动更新程序。

这里运行的代码是:

new WebClient().DownloadFile("XXXX", checkingfolder.SelectedPath);

XXX 是我的网络服务器,它在 verio 中作为 VPS 服务器运行,具有最新的 IIS 和一切。

当用户单击下载按钮时,它会显示:

'An exception occurred during a WebClient request.

问题是,我什至不知道为什么 - 我只是在尝试捕获。

这里有人知道为什么会发生这种情况吗?

感谢您给我的任何帮助,您不知道您在这里帮助了我多少 - 再次感谢!


如果我指定,我可以重现此内容,如seems在你的例子中,folder名称而不是file命名目的地。供应一个file名称代替。

作为旁白;如果我看InnerException,它告诉我问题与文件路径有关:

using(var client = new WebClient())
{
    try
    {
        client.DownloadFile(
            "http://stackoverflow.com/questions/8033619/an-exception-occurred-durning-a-webclient-request-c-sharp-asp-net/8033687#8033687",
            @"j:\MyPath");
    }
    catch (Exception ex)
    {
        while (ex != null)
        {
            Console.WriteLine(ex.Message);
            ex = ex.InnerException;
        }
    }
}

这使:

An exception occurred during a WebClient request.
Access to the path 'j:\MyPath' is denied.

如果我把它改成file,它工作正常:

client.DownloadFile(
    "http://stackoverflow.com/questions/8033619/an-exception-occurred-durning-a-webclient-request-c-sharp-asp-net/8033687#8033687",
    @"j:\MyPath\a.html");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 C# ASP.NET 时“WebClient 请求期间发生异常” 的相关文章

随机推荐