I am trying to implement an autocomplete function on a textbox which pulls data from our database using the AutoCompleteExtender from the AJAX Toolkit. The textbox and control are on a user control nested on an aspx page (which has an updatepanel); the script manager is on the master page.

<asp:TextBox ID="txtTowelManufacturer" runat="server" Width="200px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="txtTowelManufacturer_AutoCompleteExtender" 
    runat="server" MinimumPrefixLength="1" ServiceMethod="GetCompletionList"
    TargetControlID="txtTowelManufacturer" UseContextKey="True">
</ajaxToolkit:AutoCompleteExtender>

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
    ...
}

When I run the page on my dev box using cassini, using the extender generates a 401 Unauthorized error with no further debugging information. The post is correct and the response is empty:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

If I manually specify the ServicePath either directly or using a relative path, I get the same error. If I specify an incorrect path it correctly generates a 404 Not Found error, so I know it is looking at the right place.

I have been unable to figure out why I am getting an authentication error in this situation. We are not using Windows Authentication or crossing any domains, and while 401 issues have been raised many times none of the solutions presented have worked for many,

Any leads to try would be appreciated.

有帮助吗?

解决方案

Try moving the GetCompletionList() method from the user control's ascx.cs file to the page's aspx.cs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top