2012-04-20 69 views
0

我想連接遠程服務器中的xml文件。我寫了我這樣的代碼:登錄失敗:未知的用戶名或密碼錯誤?但我正在使用正確的用戶名和密碼

string XMLPATH = @"\\10.222.54.141\c$\Data\CL\Casinolink30\BuildFiles\Logging\980\NoLog4NetFile.UnitTest.Tests.nunit-results.xml"; 
     FileWebRequest request = (FileWebRequest)FileWebRequest.Create(XMLPATH); 
     request.Credentials = new NetworkCredential("administrator", "Igtcorp123"); 
     FileWebResponse response = request.GetResponse() as FileWebResponse; 
     Stream stReader = response.GetResponseStream(); 
     XmlTextReader reader = new XmlTextReader(stReader); 
     int count = 100; 
     while (reader.Read()) 
     { 
      if (reader.NodeType == XmlNodeType.Element) 
      { 
       if (reader.Name == "test-case") 
       { 

        //Console.WriteLine("testcase name:" + reader.GetAttribute("name")); 
        Console.WriteLine("testcase info"); 
        Console.WriteLine("name: " + reader.GetAttribute("name").ToString()); 
        //Console.WriteLine("success: " + reader.GetAttribute("success").ToString()); 
        Console.WriteLine("------------------------------------"); 
       } 
      } 
     } 

我得到了一個錯誤:「登錄失敗:未知的用戶名或錯誤」。 我嘗試這樣做:

  1. 輸入地址(10.222.54.141 \ C $ \ DATA \ CL \ Casinolink30 \構建文件\登錄\ 980 \ NoLog4NetFile.UnitTest.Tests.nunit-results.xml)至地址欄,然後打開。一個對話框顯示讓我添加用戶名和密碼。我輸入了正確的單詞,並且我成功訪問了該文件。
  2. 我運行上面的代碼。我成功地獲得了數據。
  3. 我在另一臺電腦上試用這個程序。他們可以訪問該地址,但該程序不起作用。

我對此感到困惑嗎?爲什麼會發生?

現在我部署我的項目到服務器,我可以成功地獲取我的數據在本地主機地址(http:// localhost:61547 /)在服務器上。但是我無法通過addr遠程獲取數據:http://10.222.54.140:8080/。發生什麼事?誰能幫我?非常感謝。

+2

這裏有一個猜想:當您從資源管理器中手動登錄,用戶名(管理員)會自動域名(MYDOMAIN \前綴管理員)。嘗試明確指定域名作爲「NetworkCredential」構造函數中的第三個參數。 – 2012-04-20 08:56:45

+0

繼以@ AvnerShahar-Kashtan之後 - [這裏](http://msdn.microsoft.com/en-us/library/system.net.networkcredential.aspx)是指向文檔的鏈接。 – Bridge 2012-04-20 11:38:44

+0

有消息顯示:訪問路徑'\\ 10.222.53.125 \ c $ \ Data \ CL \ Casinolink30 \ BuildFiles \ Logging \ 980 \ Pgic.CasinoLink.I nterfaces.Gsa.S2S.RegisterClientPlugIn.Test。 nunit-results.xml「被拒絕。但我輸入了我的用戶名和密碼。 有什麼問題? – 2012-04-25 08:51:28

回答

1

嘗試改變app.config文件位:

<system.net> 
    <defaultProxy useDefaultCredentials="false"> 
     <proxy usesystemdefault="true"/> 
    </defaultProxy> 
    </system.net> 

這可能會解決這個問題。

您可以在Web.config文件,如下補充一點:

<?xml version="1.0"?> 

<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 

<configuration> 
    <connectionStrings> 
    <add name="ApplicationServices" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <system.net> 
    <defaultProxy useDefaultCredentials="false"> 
     <proxy usesystemdefault="True"/> 
    </defaultProxy> 
    </system.net> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
    </authentication> 
+0

我的項目是ASP.NET網站,我嘗試在web.config中找到,但是我找不到它。那麼我現在可以做什麼? – 2012-04-23 01:29:23

+0

@JackZhang ...你可以在Web.config文件中找到它...我已經在上面編輯過了.... – Milee 2012-04-23 07:35:14

+0

現在我將我的項目部署到了​​服務器,我可以成功地將我的數據取到本地主機地址(http:/// localhost:61547 /)在服務器上。但我無法通過addr遠程獲取數據:http://10.222.54.140:8080/。發生什麼事?誰能幫我?非常感謝 – 2012-04-25 01:33:27

相關問題