I have got a web service programmed in c# / asp.net.
[WebService(Namespace = \"http://example.com/\")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProf
The return Forbid();
creates a ForbidResult (Status403Forbidden by default).
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.forbid?view=aspnetcore-3.1
Context.Response.StatusCode = 403;
Forbidden 403 would be a result of access to forbidden content on your website. I think what you want here is to return a message as part of your Result that is "User is not logged on"
Your web service requests will first encounter your global.asax file. You can check & return there.
You don't need to set both Context.Response.Status
and Context.Response.StatusCode
. Simply setting
Context.Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden
will automatically set Response.Status
for you.
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();
}
}