【问题标题】:WebMethod not called (triggered) by PageMethod in Visual Studio 2013WebMethod 未由 Visual Studio 2013 中的 PageMethod 调用(触发)
【发布时间】:2014-01-13 12:58:47
【问题描述】:

我有以下问题:

在 Visual Studio 2013(ASP.NET WebForms 应用程序)中创建的项目上未完成来自 WebMethod 的调用。例如,如果我在 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”,则不起作用...

可以交叉引用吗?还是一些不同的设置?

【问题讨论】:

  • Você vai querer dar uma olhada nesse site para Português: br.stackoverflow.com
  • 问题必须是英语。
  • 谢谢,我会在那里问问题..
  • 我也翻译了这个问题..
  • “webmethod 未被调用”是什么样的?您是否在客户端收到错误,可能在调试器控制台中? JavaScript 正在执行吗?

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


【解决方案1】:

我找到了解决问题的方法:阻止调用 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>

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

【讨论】:

  • 我尝试了上面的方法,但这使得 ScriptManager 停止工作,我无法使用 webopt 标签。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多