locked
asp.net.core wep api 405 method not allowed error RRS feed

  • Question

  • I have a Get Method like below , When I am testing in VS environment with postman ,it was return a error 405 Method Not Allowed

     [HttpGet]
        public IActionResult GetAllData()
        {
          var sorgu = "SELECT CODE,NAME,CITY FROM CUSTOMER";

          using (var db=new BulutContext())
          {
            var adap=new SqlDataAdapter(sorgu, db.Database.GetConnectionString());
            var dt = new DataTable();
            adap.Fill(dt);     
            

            List<Customers> model = new List<Customers>();
            model = (from DataRow dr in dt.Rows
              select new Customers
              {
                CODE = dr[0].ToString(),
                NAME = dr[1].ToString(),
                CITY = dr[2].ToString()           
              
              }).ToList();

            return Ok(model);
          }
      
            services.AddCors(c =>
          {
            c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
          });
      
      app.UseCors(options => options.AllowAnyOrigin());

    Sunday, December 13, 2020 4:30 PM

All replies

  • Merhabalar;

    Aşağıdaki şekilde bir Get metodum var , postman ile test ettigimde 405 hatası alıyorum

     [HttpGet]
        public IActionResult GetAllData()
        {
          var sorgu = "SELECT CODE,NAME,CITY FROM CUSTOMER";

          using (var db=new BulutContext())
          {
            var adap=new SqlDataAdapter(sorgu, db.Database.GetConnectionString());
            var dt = new DataTable();
            adap.Fill(dt);     
            

            List<Customers> model = new List<Customers>();
            model = (from DataRow dr in dt.Rows
              select new Customers
              {
                CODE = dr[0].ToString(),
                NAME = dr[1].ToString(),
                CITY = dr[2].ToString()           
              
              }).ToList();

            return Ok(model);
          }
      
            services.AddCors(c =>
          {
            c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
          });
      
      app.UseCors(options => options.AllowAnyOrigin());

    Sunday, December 13, 2020 4:26 PM
  • Hi Aly14,

    Thank you for posting here.

    Since your question is more related to asp.net core, you can post your question on the following forum for more help.

    ASP.NET Core

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    Visual Basic and CLR forum will be migrating to a new home on Microsoft Q&A! (VB.NET and CLR) We invite you to post new questions in the new home on Microsoft Q&A ! For more information, please refer to the sticky post(VB.NET and CLR).

    Monday, December 14, 2020 3:13 AM