Asp.Net web service: I would like to return error 403 forbidden

后端 未结 9 764
轻奢々
轻奢々 2020-12-01 13:38

I have got a web service programmed in c# / asp.net.

[WebService(Namespace = \"http://example.com/\")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProf         


        
9条回答
  •  隐瞒了意图╮
    2020-12-01 14:25

    You can protect all your methods by placing the code in your WebService constructor. This prevents your WebMethod from even being called:

    public Service(): base()
    {
        if (!GetUser().LoggedIn)
        {
            Context.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
            Context.Response.End();
        }
    }
    

提交回复
热议问题