2016-12-25 44 views
0

即時通訊從Azure web服務web應用程序使用簡單的ASP.net應用程序 我有這樣的代碼,它應該使我能夠將文件上傳到我運行相同的服務器web應用程序。 這樣的:使用ASP.net mvc上傳文件到azure iis web應用程序失敗

try 
{ 

    FtpWebRequest r = (FtpWebRequest)WebRequest.Create("ftp://www.ftp.azurewebsites.windows.net/site/wwwroot/myfiles/FTP"); 
    r.KeepAlive = true; 
    r.UseBinary = true; 
    r.Method = WebRequestMethods.Ftp.UploadFile; 
    r.Credentials = new NetworkCredential("myapp\userA","password123"); 
    FileStream fs = System.IO.File.OpenRead(source + "sourceFile.json"); 
    byte[] fileBytes = new byte[fs.Length]; 
    fs.Read(fileBytes, 0, fileBytes.Length); 
    fs.Close(); 
    r.ContentLength = fileBytes.Length; 
    r.UsePassive = false; 
    r.UseBinary = true; 
    r.ServicePoint.ConnectionLimit = fileBytes.Length; 
    r.EnableSsl = false; 
    using (Stream requestStream = r.GetRequestStream()) 
    { 
     requestStream.Write(fileBytes, 0, fileBytes.Length); 
     requestStream.Close(); 
    } 
    FtpWebResponse rs = (FtpWebResponse)r.GetResponse(); 
    rs.Close(); 
catch (WebException ex) 
{ 
    throw new Exception((ex.Response as FtpWebResponse).StatusDescription); 
} 

2怪事happning,
當我運行從Visual Studio代碼在本地我沒有拋出異常 但文件永遠不會創建 1。
2.當我從我的web應用程序即時得到運行這段代碼:

500 (Internal Server Error) 

這裏有什麼問題?

+0

你解決了這個問題嗎? –

回答

0

請在初始化新的WebRequest時嘗試指定文件名。有關如何使用FTP上傳文件的更多信息,請參閱this link

FtpWebRequest r = (FtpWebRequest)WebRequest.Create("ftp://waws-prod-hk1-021.ftp.azurewebsites.windows.net/site/wwwroot/myfiles/FTP/sourceFile.json"); 

enter image description here

當我從我的web應用程序即時得到運行這段代碼:500(內部服務器錯誤)

您可以啓用remote debugging feature調試代碼,之後您解決將應用程序部署到Azure應用服務。

相關問題