question

TaB-8489 avatar image
0 Votes"
TaB-8489 asked TaB-8489 commented

Is it possible to host a rest api in azure web app resource

Team,

I have created a simple webapp resource and I have created a rest api in visual studio 2019 .net framework 4.7.2. It doesn't have any web page. It has only 2 methods

  public class DirectController : ApiController  {
         [Route("")]
         [HttpGet]
         public HttpResponseMessage Help()
         {          
             return new HttpResponseMessage() { Content = new StringContent("123"), StatusCode = HttpStatusCode.OK};
         }
    
            
         [HttpPost]
         [Route("api/v1/group")]            
         public async Task<HttpResponseMessage> Users([System.Web.Http.FromBody] string group)
         {
             return new HttpResponseMessage() { Content = new StringContent("Not possible",Encoding.UTF8, 
                "text/plain"),StatusCode=HttpStatusCode.BadRequest };
         }
 }

Routeconfig.cs

 routes.MapRoute(
             name: "Default",
             url: "{controller}/{action}/{id}",
             defaults: new
             {
                 controller = "Direct",
                 action = "Help",
                 id = UrlParameter.Optional
             }
         );

WebAPIConfig.cs

 config.MapHttpAttributeRoutes();
                
             config.Routes.MapHttpRoute(
                 name: "DefaultApi",
                 routeTemplate: "api/{controller}/{id}",
                 defaults: new { id = RouteParameter.Optional }
             );

The moment I host rest api I get 2 different errors.

  1. When I open the site then this one

    You do not have permission to view this directory or page.

  2. When open site/api/v1/users?group=abcd then this error

    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Any suggestion please. I'm pretty stuck with this issue.

azure-webapps-developmentazure-webapps-apis
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@karishmatiwari-msft , Hello Karishma, hope you're doing well. Sorry for tagging you but could you please help me here.

0 Votes 0 ·

1 Answer

TaB-8489 avatar image
0 Votes"
TaB-8489 answered TaB-8489 commented

Its resolved. I was using web app resource but need to use api app resource if no web page/default page is there in the project.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad you were able to resolve your issue @TaB-8489 . Thanks for sharing the solution that worked for you.

1 Vote 1 ·

@Grmacjon-MSFT , Welcome :).

Just after posting the solution I got the solution. If possible could you please help with this problem as well. I would be grateful. I am facing a big challenge here.


0 Votes 0 ·