Basit Khan

Basit Khan

  • NA
  • 336
  • 122.5k

Cross Domain Web Services in ASP.Net

Apr 12 2015 6:16 AM
Dear,

I Created web services in ASP.Net, its working fine but how to do the Cross Domain.

I wrote below code to get the result in JSON format.

<webmethod,> _
Public Function GetUserDetails() As String
Dim dt As New DataTable()
Using con
Using cmd As New OleDb.OleDbCommand("SELECT * FROM Mst_User", con)
con.Open()
Dim da As New OleDb.OleDbDataAdapter(cmd)
da.Fill(dt)
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
Return serializer.Serialize(rows)
End Using
End Using
End Function

I put the code in Web.config file

Hide Copy Code
<system.webServer>   <httpProtocol>     <customHeaders>       <add name="Access-Control-Allow-Origin" value="*" />       <add name="Access-Control-Allow-Headers" value="Content-Type" />     </customHeaders>   </httpProtocol> </system.webServer>   <system.web.extensions>   <scripting>     <webServices>       <jsonSerialization maxJsonLength="1024242"></jsonSerialization>     </webServices>   </scripting> </system.web.extensions>

What i need to do more to get the Cross domain.

Thanks
Basit.

Answers (1)