asp.net中的500内部服务器错误 [英] 500 Internal Server Error in asp.net

查看:102
本文介绍了asp.net中的500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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);}.


  [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代码概述:

以下是我的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>

以下是我的Javascript函数

Below is my Javascript Function

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代码概述:

以下是我的自定义类

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

以下是Datatable方法

Below is the Datatable method

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;
 }

以下是WebMethod

Below is the 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.

推荐答案

根据属性WebMethod的文档:

According to the documentation of the attribute WebMethod:

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


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

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.

我想,Jon Skeet是对的。 :)

I guess, Jon Skeet is right. :)

这篇关于asp.net中的500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆