Send ERROR Json-Result to Client in ASP.NET 4.8

علی ذوالفقار
1402/11/18 20:17:49 (162)
web.confgi : 
    <system.webServer>
      <httpErrors errorMode="Detailed" />
      <asp scriptErrorSentToBrowser="true"/>
    </system.webServer>
        
in as.net.vb/cs file : 
    Try
        ...
    Catch ex As WebException
	Dim Result = New With {.success = False, .error = ErrorMessage, .body = Body}
        Response.Headers.Add("Content-type", "application/json")
        Response.Headers.Add("Access-Control-Allow-Origin", "*")
        Response.StatusCode = HttpStatusCode.InternalServerError
        Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(Result))
        Response.End()
    End Try
Back