vb.net WebMethod 未由 Visual Studio 2013 中的 PageMethod 调用(触发)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21091935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WebMethod not called (triggered) by PageMethod in Visual Studio 2013
提问by Leonan Milani
I have the following problem:
我有以下问题:
The call from a WebMethod is not being done on a project created in Visual Studio 2013 (ASP.NET WebForms Application). If I create a project, for example, in Visual Studio 2008 and migrate to VS 2013 works correctly. The problem only occurs when I create a new project in Visual Studio 2013. There is no error message in the console. The WebMethod is just not being called. Nothing happens. I searched a lot but found nothing about it.
在 Visual Studio 2013(ASP.NET WebForms 应用程序)中创建的项目上未完成来自 WebMethod 的调用。例如,如果我在 Visual Studio 2008 中创建一个项目并迁移到 VS 2013 工作正常。仅当我在 Visual Studio 2013 中创建新项目时才会出现此问题。控制台中没有错误消息。WebMethod 只是没有被调用。没发生什么事。我搜索了很多,但一无所获。
ASPX code:
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 code:
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
Has anyone tried this or know of a solution? I have no idea what to do ...
有没有人试过这个或知道解决方案?我不知道该怎么做 ...
EDIT:
编辑:
Guys, I discovered one more information now:
伙计们,我现在又发现了一个信息:
Working only in VS2013:
仅适用于 VS2013:
-New project. -Web - ASP.NET Web Application. -Select the template "Empty". -Insert a page "Default.aspx", the WebMethod works normally ...
-新项目。-Web - ASP.NET Web 应用程序。- 选择模板“空”。- 插入页面“Default.aspx”,WebMethod正常工作...
Now, if you create a new project and select the template "WebForms", does not work ...
现在,如果您创建一个新项目并选择模板“WebForms”,则不起作用...
Can be cross-referenced? or some different setting?
可以交叉引用吗?或一些不同的设置?
采纳答案by Leonan Milani
I found the solution to my problem: What prevented the WebMethod was called was the reference to "System.Web.Optimization". Not sure how he does it, but as I will not use it at the time, decided to remove:
我找到了解决我的问题的方法:阻止调用 WebMethod 的是对“System.Web.Optimization”的引用。不知道他是怎么做的,但由于我当时不会使用它,决定删除:
"System.Web.Optimization" and "Microsoft.AspNet.Web.Optimization.WebForms"
“System.Web.Optimization”和“Microsoft.AspNet.Web.Optimization.WebForms”
It is also necessary to remove the web.config as follows:
还需要删除 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>
All ok now! Thanks to everyone who helped me with the problem! :)
现在一切都好!感谢所有帮助我解决问题的人!:)
回答by Babloo Singh
Add this section in web.config after httpModules.
在 web.config 中httpModules之后添加此部分。
add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

