You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法访问App_Code文件夹中Web Service,FullCalendar调用VB.Net服务遇404错误

搞定FullCalendar无法访问VB.NET Web Service的404问题

兄弟,你遇到的核心问题其实是**/App_Code/文件夹的特殊性**——这是ASP.NET的私有代码目录,里面的文件只会被后台编译,根本不能直接通过浏览器URL访问,这就是你直接访问出404的原因!下面给你一步步拆解解决:

1. 先把Web Service移出/App_Code/

把你的VB.NET Web Service文件(比如CalendarService.asmx)从/App_Code/挪到网站根目录,或者新建一个公开的子目录(比如/Services/)。ASP.NET不会把/App_Code/里的文件当作可访问的Web服务端点,移完之后先测试访问新路径,比如http://你的站点地址/Services/CalendarService.asmx,如果能看到Web Service的默认描述页面,这一步就搞定了。

2. 给Web Service加对关键属性

你的Web Service类必须标记允许AJAX访问的属性,不然FullCalendar的请求会被拒绝,还要指定返回JSON格式(适配FullCalendar的需求),示例代码如下:

<WebService(Namespace:="http://your-custom-namespace.com/")> ' 建议替换成自己的命名空间,别用tempuri
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<System.Web.Script.Services.ScriptService> ' 这个是AJAX访问的关键!
Public Class CalendarService
    Inherits System.Web.Services.WebService

    <WebMethod()>
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> ' 指定返回JSON
    Public Function GetEvents() As List(Of YourEventModel)
        ' 这里写从数据库或其他地方获取事件的逻辑,返回符合FullCalendar格式的列表
    End Function
End Class

3. 调整FullCalendar的事件源配置

确保FullCalendar的events选项指向正确的Web Service方法URL,而且请求格式要匹配ASMX的要求:

document.addEventListener('DOMContentLoaded', function() {
  const calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
    events: {
      url: '/Services/CalendarService.asmx/GetEvents',
      method: 'POST', // ASMX Web Service默认用POST请求
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      },
      // 如果你的方法需要日期范围参数,加上这个data函数
      data: function(info) {
        return JSON.stringify({
          startDate: info.startStr,
          endDate: info.endStr
        });
      },
      failure: function() {
        alert('事件加载失败,检查服务配置哦');
      }
    }
  });
  calendar.render();
});

4. 检查Web.config的必要配置

确保Web.config里启用了HTTP请求协议,并且引用了正确的程序集:

<system.web>
  <webServices>
    <protocols>
      <add name="HttpGet"/>
      <add name="HttpPost"/>
    </protocols>
  </webServices>
  <compilation debug="true" targetFramework="4.8">
    <assemblies>
      <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </assemblies>
  </compilation>
</system.web>

5. 最后排查服务器设置

  • 如果用IIS,确保应用程序池的.NET版本和你的Web Service目标版本一致(比如4.8),而且处理程序映射里存在asmx对应的处理程序。
  • 如果用Visual Studio的IIS Express,重启服务器,清理解决方案后重新编译再测试。

按这个顺序一步步来,先解决404的问题(挪服务位置),再验证服务能返回JSON,最后调整FullCalendar的请求,应该就能顺利拉取事件了!

内容的提问来源于stack exchange,提问作者Saul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:09:25