Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

[WebService(Namespace = "http://example.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] [System.ComponentModel.ToolboxItem(false)] public class Service: System.Web.Services.WebService {      [WebMethod]     [ScriptMethod(ResponseFormat = ResponseFormat.Json)]     public Result GetData()     {         User user = GetUser();          if (user.LoggedIn)         {             return GetData();         }         else         {             // raise exception -> return error 403         }     } 

How is it possible to return error 403 out of this web service? I can throw an exception - but this shows the exeption and not his error.

Any ideas?

like image 486
bernhardrusch Avatar asked Apr 13 '11 13:04

bernhardrusch


People also ask

Is ASP NET core 403 forbidden access is denied?

This means that an ASP.NET application deployed inside the root folder already has Read and Execute permissions to its application folders. However, if your ASP.NET application needs to use files or folders in other locations, you must specifically enable access.

Why do I keep seeing 403 Forbidden?

The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it. This status is similar to 401 , but for the 403 Forbidden status code re-authenticating makes no difference.

Can you bypass a 403 error?

How to Bypass 403 restrictions? There are many headers and paths which you can use to bypass 403 restrictions. Adding Headers in request :By adding different headers in request with value 127.0. 0.1 can also help in bypassing restrictions.


1 Answers

If you were using MVC you'd do the following:

            return new HttpStatusCodeResult(HttpStatusCode.Forbidden); 
like image 148
Bryan Legend Avatar answered Oct 10 '22 07:10

Bryan Legend