WebClient.DownloadFile - Security Problem

Discussion in 'Site Programming, Development and Design' started by silentthread, Nov 22, 2012.

  1. Hi, this web method works okay on my local environment, but not on Winhost


    Code:
        [WebMethod]
        public void TestDownloadFile() 
        {
            WebClient wc = new WebClient();
            wc.DownloadFile("http://sports.yahoo.com/nba/scoreboard", "site.txt");
        }
    
    I get the following error message....

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    at System.Net.WebClient.DownloadFile(Uri address, String fileName)
    at System.Net.WebClient.DownloadFile(String address, String fileName)
    at Service.TestDownloadFile()


    Is there location where we are allowed to save files to?
     
    Last edited by a moderator: Oct 14, 2015
  2. Problem fixed.


    These are the 2 things that needed to be done...

    <system.web>
    <trust level="Full"/>

    and

    Code:
        [WebMethod]
        public void TestDownloadFile() 
        {
            WebClient wc = new WebClient();
            wc.DownloadFile("http://sports.yahoo.com/nba/scoreboard", HttpRuntime.AppDomainAppPath + "\\site.txt");
        }
    
     
  3. Glad you got it worked out, thanks for posting the fix info.
     

Share This Page