Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. The requested resource does not support http method 'GET'

The requested resource does not support http method 'GET'

Scheduled Pinned Locked Moved ASP.NET
csharpdatabaseasp-netcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    Good Day All i have a web api with a controller like this

    public class RegistrationController : ApiController

    {
    
        \[System.Web.Http.AcceptVerbs("GET", "POST")\]
    
        \[System.Web.Http.HttpGet\]
    
        public int Get(\[FromBody\]Registration model)
    
        {
    
            try
    
            {
    
                GetMyContact.Services.Database.Database db = new Database.Database();
    
                db.RegisterUser(model); 
    
                var response = Request.CreateResponse(HttpStatusCode.Created, string.Empty);
    
                string uri = Url.Link("DefaultApi", new { id = model.USER\_ID });
    
                response.Headers.Location = new Uri(uri);
    
                return model.USER\_ID;
    
            }
    
            catch(Exception ex)
    
            {
    
                HttpStatusCode statusCode = HttpStatusCode.BadRequest; 
                var errResponse = Request.CreateResponse(statusCode, ex.Message);
    
                throw new HttpResponseException(errResponse);
    
            } 
    
        }
    
    }
    

    and the config is like this

    config.Routes.MapHttpRoute(

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

    and i am testing it using the following URL just to see if i will hit that breakpoint http://localhost:39194/api/Registration but i get the following error on the browser The requested resource does not support http method 'GET'. Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

    A 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      Good Day All i have a web api with a controller like this

      public class RegistrationController : ApiController

      {
      
          \[System.Web.Http.AcceptVerbs("GET", "POST")\]
      
          \[System.Web.Http.HttpGet\]
      
          public int Get(\[FromBody\]Registration model)
      
          {
      
              try
      
              {
      
                  GetMyContact.Services.Database.Database db = new Database.Database();
      
                  db.RegisterUser(model); 
      
                  var response = Request.CreateResponse(HttpStatusCode.Created, string.Empty);
      
                  string uri = Url.Link("DefaultApi", new { id = model.USER\_ID });
      
                  response.Headers.Location = new Uri(uri);
      
                  return model.USER\_ID;
      
              }
      
              catch(Exception ex)
      
              {
      
                  HttpStatusCode statusCode = HttpStatusCode.BadRequest; 
                  var errResponse = Request.CreateResponse(statusCode, ex.Message);
      
                  throw new HttpResponseException(errResponse);
      
              } 
      
          }
      
      }
      

      and the config is like this

      config.Routes.MapHttpRoute(

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

      and i am testing it using the following URL just to see if i will hit that breakpoint http://localhost:39194/api/Registration but i get the following error on the browser The requested resource does not support http method 'GET'. Thanks

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

      A Offline
      A Offline
      Akhil Mittal
      wrote on last edited by
      #2

      Try executing it by removing ,

      [System.Web.Http.AcceptVerbs("GET", "POST")]
      [System.Web.Http.HttpGet]

      Since your action name is Get , it will automatically be executed with Get Verb.

      Thanks Do not forget to comment and rate the article if it helped you by any means.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups