WebMethod未在Visual Studio 2013中由PageMethod调用(触发)

时间:2014-01-13 12:58:47

标签: asp.net vb.net visual-studio-2013 webmethod pagemethods

我有以下问题:

WebMethod的调用未在Visual Studio 2013(ASP.NET WebForms Application)中创建的项目上完成。如果我创建一个项目,例如,在Visual Studio 2008中并迁移到VS 2013正常工作。只有在Visual Studio 2013中创建新项目时才会出现此问题。控制台中没有错误消息。 WebMethod没有被调用。什么都没发生。我搜索了很多但却一无所获。

ASPX代码:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestePageMethods._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />

    <script type="text/javascript">

        function testeClick() {            
            PageMethods.SayHello("Name");        
        }  

    </script>

    <input type="button" value="Say Hello" onclick="testeClick();" />
    </form>
</body>
</html>

ASPX.VB代码:

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    <System.Web.Services.WebMethod(True)> _
    Public Shared Function SayHello(ByVal name As String) As String
        Return "Hello " & name
    End Function

End Class

有没人试过这个或知道解决方案?我不知道该怎么做......

编辑:

伙计们,我现在又发现了一个信息:

仅在VS2013中工作:

- 新项目。 -Web - ASP.NET Web应用程序。 - 选择模板“空”。 - 插入一个页面“Default.aspx”,WebMethod正常工作......

现在,如果您创建一个新项目并选择模板“WebForms”,则无效...

可以交叉引用吗?或者一些不同的设置?

2 个答案:

答案 0 :(得分:3)

我找到了我的问题的解决方案:阻止WebMethod被调用的是对“System.Web.Optimization”的引用。不确定他是怎么做到的,但由于我当时不会使用它,所以决定删除:

“System.Web.Optimization”和“Microsoft.AspNet.Web.Optimization.WebForms”

还需要删除web.config,如下所示:

<namespaces>
    <add namespace="System.Web.Optimization" />
</namespaces>

<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" 

namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />

<dependentAssembly>
        <assemblyIdentity name="WebGrease" culture="neutral" 

publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>

现在一切都好!感谢所有帮助我解决问题的人! :)

答案 1 :(得分:0)

httpModules 之后在web.config中添加此部分。

add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"