WebClient.DownloadData()使用.axd返回404

时间:2015-01-29 19:28:07

标签: c# asp.net-mvc webclient system.net webresource.axd

我正在尝试下载.axd图片链接,但我找不到错误(404)。 在本地服务器中,工作正常,但我在生产服务器上获得404。我必须在web.config中设置什么东西吗?

    public System.Drawing.Image DownloadImage(string url)
    {
        using (var webClient = new WebClient())
        {
            byte[] fileBytes;
            try
            { 
            fileBytes= webClient.DownloadData(url);
            }
            catch (WebException ex)
            {
               // (HttpWebResponse)ex.Response).StatusCode
                Util.GerarLog("DownloadImage", ex.Message + " " + ex.InnerException + "URL: " + url + "Response: " + ((HttpWebResponse)ex.Response).StatusCode.ToString(), "Image");
                throw new Exception(ex.Message + " " + ex.InnerException);
            }
           return ByteArrayToImage(fileBytes);
        }
    }

    public static System.Drawing.Image ByteArrayToImage(byte[] fileBytes)
    {
        using (var stream = new MemoryStream(fileBytes))
        {
            return System.Drawing.Image.FromStream(stream);
        }
    }

0 个答案:

没有答案