亲爱的所有我如何在Asp.net Web服务方法中设置响应状态?
<WebMethod()> _
<Script.Services.ScriptMethod(responseFormat:=Script.Services.ResponseFormat.Json)> _
Public Function HelloWorld(ByVal name As String, ByVal userID As String, ByVal email As String, ByVal department As String, ByVal password1 As String) As String
Dim result As String
Try
Dim param(6) As SqlParameter
param(0) = New SqlParameter("@RefId", 1)
param(1) = New SqlParameter("@Name", name)
param(2) = New SqlParameter("@UserName", userID)
param(3) = New SqlParameter("@Email", email)
param(4) = New SqlParameter("@Department", department)
param(5) = New SqlParameter("@Password", password1)
' param(6) = New SqlParameter("@CreatedBy", "")
result = SqlHelper.ExecuteNonQuery(connStringShareMe, Data.CommandType.StoredProcedure, "Users_Insert", param)
Return "Done"
Catch ex As Exception
Return "500"
Return result
End Try
End Function
我想返回500状态代码作为回应我该怎么办?
答案 0 :(得分:5)
您需要通过静态HttpContext类访问:
HttpContext.Current.Response.StatusCode = 500