【问题标题】:How do I add Access-Control-Allow-Origin to an ASMX webservice I have created in VB?如何将 Access-Control-Allow-Origin 添加到我在 VB 中创建的 ASMX Web 服务?
【发布时间】:2010-11-05 15:36:52
【问题描述】:

我有一个非常简单的 ASMX 页面...

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services

<WebService(Namespace:="http://localhost/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
Public Class JSWSGuessWeddingsByDay
    Inherits System.Web.Services.WebService


    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
    Public Function HowManyPeopleAreGettingMarriedToday() As Integer

        Dim weddingCount As New Controller.Member.MemberDal

        Return weddingCount.GuessWeddingsByDay(Nothing)

    End Function
End Class

如何将 Access-Control-Allow-Origin 添加到响应标头中,以便使用 AJAX 的多个网站可以使用 Web 服务?

【问题讨论】:

  • 顺便说一句,它不是任何类型的“页面”。

标签: ajax vb.net asmx


【解决方案1】:

您是否尝试在您的退货声明之前添加此内容?:

Response.AddHeader("Access-Control-Allow-Origin","*")

【讨论】:

  • 这是一个网络服务,你必须使用 Context.Response.AppendHeader("..")
猜你喜欢
  • 2016-06-10
  • 1970-01-01
  • 2013-04-08
  • 1970-01-01
  • 2020-01-01
  • 1970-01-01
  • 2018-06-24
  • 2011-06-27
相关资源
最近更新 更多