asp.net中有500个内部服务器错误

时间:2022-11-24 08:26:41

Question Overview: I am creating an application in which I have a html select list from where I select a category and from that category I get items and there images using ajax webmethod.

问题概述:我正在创建一个应用程序,其中我有一个html选择列表,从中我选择一个类别,从该类别我得到项目和使用ajax webmethod的图像。

Problem Overview: I faced many 500 error in ajax linq to sql and fix it. But now I am working on ado.net application and The problem which I was facing is When I select a category from select list(catlist) its shows me error from here error: function (xhr) { alert(xhr.status);}.

问题概述:我在ajax linq中遇到了500多个错误并修复了它。但现在我正在研究ado.net应用程序和我面临的问题是当我从选择列表(catlist)中选择一个类别时,它显示我从这里出错错误:function(xhr){alert(xhr.status);} 。

  [ArgumentException]: Unknown web method elist.
 Parameter name: methodName
 at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
 at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
 at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
.

How can I fix this error. I thought I briefly describe my question.

我该如何解决这个错误。我想我简要描述一下我的问题。

Default.Aspx Code Overview:

Default.Aspx代码概述:

Below is my HTML

下面是我的HTML

<table>
    <tr>
        <td>
            <select id="catlist" runat="server" onchange="getImageUrl()"></select>
        </td>
        <td></td>
    </tr>
    <tr>
        <td>
            <img id="imgload" width="180" height="100" src="" alt="No Image Found" />
        </td>
        <td>
            <ul>
                <li>Description</li>
                <li>Loreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum Ispum</li>
            </ul>
        </td>
    </tr>
</table>

Below is my Javascript Function

下面是我的Javascript函数

function getImageUrl() {
        var catid = $("#catlist")[0].value;
        $.ajax({
            url: "Default.aspx/elist",
            data: { catId: catid },
            contentType: "Application/json; charset=utf-8",
            responseType: "json",
            method: "POST",
            success: function (response) {
                alert(response.d);
            },
            error: function (xhr) {
                alert(xhr.status);
            },
            Failure: function (response) {
                alert(response);
            }
        });
    }

Default.Aspx.cs Code Overview:

Default.Aspx.cs代码概述:

Below is my custom class

以下是我的自定义课程

public class events
{
    public string EVE_NAME { get; set; }
    public string EVE_IMG_URL { get; set; }
    public string EVE_DESCRIPTION_SHORT { get; set; }
}

Below is the Datatable method

以下是Datatable方法

private static DataTable dt2(int catId)
{
    DataTable dataTable = new DataTable();
    SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=EVENT;Persist Security Info=True;User ID=sa;Password = 123");
        string query = "sp_view";

    SqlCommand cmd = new SqlCommand(query, conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@catID", SqlDbType.Int).Value = catId;
    conn.Open();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dataTable);
    return dataTable;
 }

Below is the WebMethod

下面是WebMethod

[WebMethod]
private static List<events> elist(int catId)
{
     List<events> eve = new List<events>();
     eve = (from DataRow row in dt2(catId).Rows
           select new events
           {
                   EVE_NAME = row["EVE_NAME"].ToString(),
                   EVE_IMG_URL = row["EVE_IMG_URL"].ToString(),
                   EVE_DESCRIPTION_SHORT = row["EVE_DESCRIPTION_SHORT"].ToString(),
           }).ToList();
     return eve;
 }

NOTE: Database column names and events class properties names are same.

注意:数据库列名称和事件类属性名称相同。

3 个解决方案

#1


3  

According to the documentation of the attribute WebMethod:

根据WebMethod属性的文档:

https://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.90).aspx

https://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.90).aspx

Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service. You can also use the properties of this attribute to further configure the behavior of the XML Web service method. For more information, see Code Model for XML Web Services in Managed Code.

将WebMethod属性附加到Public方法表示您希望将该方法作为XML Web服务的一部分公开。您还可以使用此属性的属性来进一步配置XML Web服务方法的行为。有关更多信息,请参阅托管代码中的XML Web服务的代码模型。

I guess, Jon Skeet is right. :)

我想,Jon Skeet是对的。 :)

#2


1  

WebMethod must be public, or it will not be reachable from outside.

WebMethod必须是公共的,否则无法从外部访问。

#3


0  

I just put [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] line after my web method attribute and make my all method associated with web method to public. Now my Clear code is:

我只是将[ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)]行放在我的web方法属性之后,并将我的所有方法与web方法关联到public。现在我的清除代码是:

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public static List<events> elist(int catId)
    {
        List<events> eve = new List<events>();
        eve = (from DataRow row in dt2(catId).Rows
               select new events
               {
                   EVE_NAME = row["EVE_NAME"].ToString(),
                   EVE_IMG_URL = row["EVE_IMG_URL"].ToString(),
                   EVE_DESCRIPTION_SHORT = row["EVE_DESCRIPTION_SHORT"].ToString(),
               }).ToList();
        return eve;
    }

    public static DataTable dt2(int catId)
    {
        DataTable dataTable = new DataTable();
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=EVENT;Persist Security Info=True;User ID=sa;Password = 123");
        string query = "sp_view";

        SqlCommand cmd = new SqlCommand(query, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@catID", SqlDbType.Int).Value = catId;
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dataTable);
        conn.Close();
        da.Dispose();
        return dataTable;
    }

#1


3  

According to the documentation of the attribute WebMethod:

根据WebMethod属性的文档:

https://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.90).aspx

https://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.90).aspx

Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service. You can also use the properties of this attribute to further configure the behavior of the XML Web service method. For more information, see Code Model for XML Web Services in Managed Code.

将WebMethod属性附加到Public方法表示您希望将该方法作为XML Web服务的一部分公开。您还可以使用此属性的属性来进一步配置XML Web服务方法的行为。有关更多信息,请参阅托管代码中的XML Web服务的代码模型。

I guess, Jon Skeet is right. :)

我想,Jon Skeet是对的。 :)

#2


1  

WebMethod must be public, or it will not be reachable from outside.

WebMethod必须是公共的,否则无法从外部访问。

#3


0  

I just put [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] line after my web method attribute and make my all method associated with web method to public. Now my Clear code is:

我只是将[ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)]行放在我的web方法属性之后,并将我的所有方法与web方法关联到public。现在我的清除代码是:

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public static List<events> elist(int catId)
    {
        List<events> eve = new List<events>();
        eve = (from DataRow row in dt2(catId).Rows
               select new events
               {
                   EVE_NAME = row["EVE_NAME"].ToString(),
                   EVE_IMG_URL = row["EVE_IMG_URL"].ToString(),
                   EVE_DESCRIPTION_SHORT = row["EVE_DESCRIPTION_SHORT"].ToString(),
               }).ToList();
        return eve;
    }

    public static DataTable dt2(int catId)
    {
        DataTable dataTable = new DataTable();
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=EVENT;Persist Security Info=True;User ID=sa;Password = 123");
        string query = "sp_view";

        SqlCommand cmd = new SqlCommand(query, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@catID", SqlDbType.Int).Value = catId;
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dataTable);
        conn.Close();
        da.Dispose();
        return dataTable;
    }