WebMethod 未由 Visual Studio 2013 中的 PageMethod 调用(触发) [英] WebMethod not called (triggered) by PageMethod in Visual Studio 2013
问题描述
我有以下问题:
在 Visual Studio 2013(ASP.NET WebForms 应用程序)中创建的项目上未完成来自 WebMethod 的调用.例如,如果我在 Visual Studio 2008 中创建一个项目并迁移到 VS 2013 工作正常.仅当我在 Visual Studio 2013 中创建新项目时才会出现此问题.控制台中没有错误消息.WebMethod 只是没有被调用.没发生什么事.我搜索了很多,但一无所获.
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.
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 代码:
ASPX.VB code:
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 ...
伙计们,我现在又发现了一个信息:
Guys, I discovered one more information now:
仅在 VS2013 中工作:
Working only in VS2013:
-新项目.-Web - ASP.NET Web 应用程序.- 选择模板空".- 插入页面Default.aspx",WebMethod正常工作...
-New project. -Web - ASP.NET Web Application. -Select the template "Empty". -Insert a page "Default.aspx", the WebMethod works normally ...
现在,如果您创建一个新项目并选择模板WebForms",则不起作用...
Now, if you create a new project and select the template "WebForms", does not work ...
可以交叉引用吗?或者一些不同的设置?
Can be cross-referenced? or some different setting?
推荐答案
我找到了解决问题的方法:阻止调用 WebMethod 的是对System.Web.Optimization"的引用.不知道他是怎么做的,但由于我当时不会使用它,决定删除:
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:
System.Web.Optimization"和Microsoft.AspNet.Web.Optimization.WebForms"
"System.Web.Optimization" and "Microsoft.AspNet.Web.Optimization.WebForms"
还需要删除 web.config 如下:
It is also necessary to remove the web.config as follows:
<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! :)
这篇关于WebMethod 未由 Visual Studio 2013 中的 PageMethod 调用(触发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!