本文介绍了WebMethod(有时)返回整个网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个接受一个参数的WebMethod.

I have a WebMethod which accepts one parameter.

当我向不带任何参数的web方法发送请求时,一切正常,但是当我向同一方法提供参数时,它将返回整个站点而不是字符串.

When I send a request to the webmethod without any parameters everything works well but when I supply a parameter to the same method, it returns entire site instead of a string.

page参数除了列表的内容外什么都不会改变.

The page parameter changes nothing except the content of the list.

列表只是ListView,它显示字符串列表.

List is just ListView which displays list of strings.

当我使用URL重写时,在我提供参数的实例中,URL重写与不提供时的实例不同.

When I use URLRewriting the URL is different in instances that I supply a parameter from instances when I do not.

有人可以帮助我解决这个问题吗?

Can anybody help me with this problem?

我的WebMethod:

My WebMethod:

[WebMethod]
public static string GetResult(int id)
{
    return "Hooray";
}

我的网络方法调用:

PageMethods.GetResult(docId,
    function onSuccess(list) {
        $(element).parent().siblings().filter(":first").append(list);
    });

不带参数的网址:
www.mywebsite.com/items重写为www.mywebsite.com/items.aspx

带有参数的网址:
www.mywebsite.com/items/1重写为www.mywebsite.com/items.aspx?id=1

推荐答案

以下是有关相同的问题可能会说明情况.基本上,它说这是不起作用的,因为处理PageMethods的处理程序正在寻找{pagename.aspx}/{methodname},并且您的url重写导致它无法识别您正在调用的是page方法.

Here's a discussion about your same issue that might shed some light on the situation. Basically, what it says is that it's not working because the handler that deals with PageMethods is looking for {pagename.aspx}/{methodname}, and your url rewriting is causing it to not recognize you are calling a page method.

该页面上的一个建议是在自动生成相同签名的调用之后,在您的javascript代码中添加以下内容:

One suggestion on that page was to add the following in your javascript code somewhere after the auto-generated call of the same signature:

PageMethods.set_path('/items.aspx');

这将使它使用实际URL而不是重写的URL来调用您的页面方法.

This will make it call your page method using the real url instead of the rewritten one.

这篇关于WebMethod(有时)返回整个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:15