【问题标题】:how to set response status in asp.net web service method如何在asp.net Web服务方法中设置响应状态
【发布时间】:2011-10-12 11:14:17
【问题描述】:

亲爱的,我如何在 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 状态码作为响应,我该怎么做?

【问题讨论】:

    标签: asp.net vb.net visual-studio


    【解决方案1】:

    需要通过静态HttpContext类访问:

    HttpContext.Current.Response.StatusCode = 500
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      • 1970-01-01
      • 2021-07-21
      相关资源
      最近更新 更多