一个Web客户端请求&QUOT期间“发生异常;而使用C#ASP.NET [英] 'An exception occurred during a WebClient request" while using C# ASP.NET

查看:504
本文介绍了一个Web客户端请求&QUOT期间“发生异常;而使用C#ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经建立了一个自动更新程序,以我的程序。

So, I have built an auto update program to my program.

这是在这里运行的代码是:

The code that is running in here is:

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



XXX是我的web服务器运行在Verio的一个VPS服务器,与最新的IIS和一切。

the XXX is my webserver that is running as a VPS server in verio, with the newest IIS and everything.

在下载按钮,用户点击,它说:

When the user clicks on the download button, it says:

'An exception occurred during a WebClient request.



的事情是,我不知道为什么 - 我只是做尝试捕捉。这里

The thing is, that I dont even know why - i am just doing try catch.

任何人有任何想法,为什么发生这种情况的任何帮助你能给我吗?

Anyone here have any idea why this happened?

谢谢,你有不知道有多少你在这里帮我 - !再次感谢

Thanks for any help you will give me, you have no idea how much you are helping me here - thanks again !

推荐答案

我可以重现这一点,如果我指定,为的似乎的是在你的榜样的情况下,文件夹的名称,而不是文件命名的目的地。 。供应的文件名称,而不是

I can reproduce this if I specify, as seems to be the case in your example, a folder name rather than a file name the destination. Supply a file name instead.

顺便说一句;如果我看的InnerException ,它告诉我,这个问题涉及文件路径:

As an aside; if I look at the InnerException, it tells me that the problem relates to the file path:

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;
        }
    }
}



其中给出:

Which gives:

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

如果我将其更改为文件,它工作正常:

If I change it to a file, it works fine:

client.DownloadFile(
    "http://stackoverflow.com/questions/8033619/an-exception-occurred-durning-a-webclient-request-c-sharp-asp-net/8033687#8033687",
    @"j:\MyPath\a.html");

这篇关于一个Web客户端请求&QUOT期间“发生异常;而使用C#ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆