2009-12-10 88 views
0

我在我的網頁中有一個文本框和Ajax autocomplexxtender。我在本地開發機器沒有問題。當我將此頁面上傳到遠程主機時,」驗證失敗。 。ExceptionType 「:」 System.InvalidOperationException」這個錯誤ASP.NET WebService:身份驗證失敗。 ExceptionType「:」System.InvalidOperationException「

這裏是我的代碼;

<form id="form1" runat="server"> 
<asp:ScriptManager ID="ScriptManager1" runat="server"> 
    <Services> 
     <asp:ServiceReference Path="~/WebService.asmx" /> 
    </Services> 
</asp:ScriptManager> 
<div> 
    <asp:TextBox ID="txtAra" runat="server"></asp:TextBox> 
    <cc1:autocompleteextender id="AutoCompleteExtender1" runat="server" servicepath="~/WebService.asmx" 
     servicemethod="IsmeGoreGetir" minimumprefixlength="1" targetcontrolid="txtAra" 
     > 
        </cc1:autocompleteextender> 
</div> 
</form> 

然後Web服務端;

OleDbConnection con; 
OleDbCommand cmd; 
OleDbDataReader dr; 


[WebMethod(EnableSession = true)] 
public string[] IsmeGoreGetir(string prefixText, int count) 
{ 
    con = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/nobetRehber.mdb")); 

    cmd = new OleDbCommand("Select * from Rehber Where AD like '" + prefixText.ToUpper() + "%'",con); 

    OleDbDataAdapter da = new OleDbDataAdapter(cmd); 
    if (con.State != ConnectionState.Open) 
     con.Open(); 

    DataTable dt = new DataTable(); 
    da.Fill(dt); 
    string[] items = new string[dt.Rows.Count]; 
    int i = 0; 
    foreach (DataRow dr in dt.Rows) 
    { 
     items.SetValue(dr["AD"].ToString(), i); 
     i++; 
    } 
    con.Close(); 
    return items; 
} 
+0

你應該真的把con和cmd變量包含在一個使用(或try/finally)塊中 – Kane

回答

2
  • 哇,我真的希望你不要上傳到面向公衆的服務器,http://sqlmap.sourceforge.net/將在幾秒鐘內擁有該網站。prefixText:=「1 = 1; DELETE * FROM Rehber; - 」是它的一個非常簡單的版本

  • 既然你場,我只能假設你有多個讀者在一個連接上你都躲在場醫生

    • 。既然是這樣的話,你也分配一個新的連接每次調用,從而導致內存泄漏。
    • 既然是這樣的話,你剛剛創作了大量的比賽條件訪問場騙子。

    • 同上for cmd。

  • dr [「AD」]。ToString()可以拋出null引用,否則會這樣做,如果db-schema與代碼脫節。

所以,如果你解決你的競爭條件和有趣的代碼,它可能實際上工作。另外,下次提供堆棧跟蹤。 :)

+1

輕鬆使用「垃圾代碼」註釋。不是每個人都是主程序員 – Kane

+0

是的,正確的。我應該冷靜下來。這很可怕。 – Henrik

+0

這不是我的問題的解決方案,但您對我的編碼問題正確。 –

0

直接在IE中從客戶端在IE中調用頁面WebService.asmx。首先檢查webservice託管到生產機器後是否可訪問。

如果它的工作。當客戶端從代碼調用服務時,檢查它需要哪種認證。

此問題與連接或命令無關。它與Web服務認證有關。

Ref。 http://support.microsoft.com/kb/813834