premetto che Ho fatto una ricerca, ed ho letto numerosi thread, risultato: mi arrendo!
Ho un sito web con framework 4, ma è un semplice webForm
1) ho scaricato e referenziato le DLL System.Web.Cors, system.web.http.Cors
2) ho implementato il beginRequest in Global.asax
codice:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim Context = HttpContext.Current
Dim Response = Context.Response
Dim Config As System.Web.Http.HttpConfiguration
Dim Cors As New EnableCorsAttribute("*", "*", "*")
' enable CORS
Response.AddHeader("Access-Control-Allow-Origin", "*")
Response.AddHeader("X-Frame-Options", "ALLOW-FROM *")
If (Context.Request.HttpMethod = "OPTIONS") Then
Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept")
Response.End()
End If
End Sub
3) ho aggiunto i riferimenti in web.config riguardo il Cors
codice:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS,PUT,DELETE" />
<add name="Access-Control-Allow-Headers" value="Content-Type,soapaction" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.webServer xmlns="">
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime xmlns="">
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
4) nel servizio web ho aggiunto i riferimenti al CORS, sia nella dichiarazione di classe che nel metodo
codice:
<EnableCors("*", "*", "*")>
<Route("api/sendrequest")>
<System.Web.Script.Services.ScriptService()>
<WebService(Namespace:="http://tempuri.org/")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Public Class PetService
Inherits System.Web.Services.WebService
<EnableCors("*", "*", "*")>
<WebMethod>
Public Function Login(user As String, pass As String) As Boolean
............
in tutti gli esempi che leggo basta una sola implementazione, BOH
non so cosa dire o fare