JSON'a yanıt veren bir ASP.NET ASMX WebMethod dosyasında, her ikisi de bir istisna atar & HTTP yanıt kodunu ayarlayabilir miyim? Bir HttpException attıysam, durum kodu uygun şekilde ayarlanabilseydim, ancak hizmetin 500 hatadan başka bir şeyle yanıt veremediğini düşündüm.HTTP Yanıt Kodunu & Bir ASMX JSON Hizmetinde Özel Durum Atma Kurabilir miyim?
Ayrıca[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void TestWebMethod() {
throw new HttpException((int)HttpStatusCode.BadRequest, "Error Message");
}
:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void TestWebMethod() {
try {
throw new HttpException((int)HttpStatusCode.BadRequest, "Error Message");
}
catch (HttpException ex) {
Context.Response.StatusCode = ex.GetHttpCode();
throw ex;
}
}
Bunlar hem 500.
Birçok sayesinde cevap
Aşağıdaki çalıştılar.
Bununla yerde aldın olacak istisna atıyor edemez zaman? –
Korkarım ki değil. – Markus