0

I created this REST API in Visual studio 2019 in .net core and in the controller class, I have the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using RecLoadAPI.DAL;
namespace RecLoadAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RecLoadPrimeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        [Route("RecLoadPrime/insertRecLoadData/{RecStartDate}/{RecEndDate}")]
        [HttpPost]
        public void insertRecLoadData(string RecStartDate, string RecEndDate)
        {
            RecLoadDataProvider dataProvider = new RecLoadDataProvider();
            dataProvider.InsertCardsData(RecStartDate, RecEndDate);
        }
    }
}

I am trying to test my code through Postman and I wrote this URL:

https://localhost:44306/api/RecLoadPrime/insertRecLoadData/?RecStartDate=01/01/2020&RecEndDate=01/02/2020

in the Postman and I keep getting the error saying Name is not defined. I am not sure what am I doing wrong.I am very new to REST API's. Below is the screen shot of Postman.

enter image description here

Below is the image of my PreRequest script:

enter image description here

Pre Requst script is taltally empty now. I am getting a different error now:

HTTP Error 500.30 - ANCM In-Process Start Failure

Below is the error:

<!DOCTYPE html>
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <title> HTTP Error 500.30 - ANCM In-Process Start Failure </title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;
            font-size: .813em;
            color: #222;
            background-color: #fff;
        }

        h1,
        h2,
        h3,
        h4,
        h5 {
            /*font-family: 'Segoe UI',Tahoma,Arial,Helvetica,sans-serif;*/
            font-weight: 100;
        }

        h1 {
            color: #44525e;
            margin: 15px 0 15px 0;
        }

        h2 {
            margin: 10px 5px 0 0;
        }

        h3 {
            color: #363636;
            margin: 5px 5px 0 0;
        }

        code {
            font-family: Consolas, "Courier New", courier, monospace;
        }

        body .titleerror {
            padding: 3px 3px 6px 3px;
            display: block;
            font-size: 1.5em;
            font-weight: 100;
        }

        a {
            color: #1ba1e2;
            text-decoration: none;
        }

        a:hover {
            color: #13709e;
            text-decoration: underline;
        }

        li {
            margin: 5px;
        }
    </style>
</head>

<body>
    <h1> HTTP Error 500.30 - ANCM In-Process Start Failure </h1>

    <h2> Common causes of this issue: </h2>
    <ul>
        <li> The application failed to start </li>
        <li> The application started but then stopped </li>
        <li> The application started but threw an exception during startup </li>
    </ul>

    <h2> Troubleshooting steps: </h2>
    <ul>
        <li> Check the system event log for error messages </li>
        <li> Enable logging the application process' stdout messages </li>
        <li> Attach a debugger to the application process and inspect </li>
    </ul>

    <h2>
        For more information visit:
        <a href="https://go.microsoft.com/fwlink/?LinkID=2028265">
            <cite> https://go.microsoft.com/fwlink/?LinkID=2028265 </cite></a>
    </h2>

</body>

</html>

Any help will be highly appreciated.

Anjali
  • 2,540
  • 7
  • 37
  • 77
  • 1
    What code you have in PreRequest Script? – Chetan Mar 13 '20 at 15:39
  • Show us your Pre-request script. Th problem doesn't related to your app. You have an error in Pre-request script in Postman (Pre-request script tab) – Roman Marusyk Mar 13 '20 at 15:40
  • 1
    try this in postman: `https://localhost:44306/api/RecLoadPrime/insertRecLoadData/01%2F01%2F2020/01%2F02%2F2020` You need to encode the dates and you also have too much in the url. – Icculus018 Mar 13 '20 at 15:43
  • @kristech The error says: There was an error in Pre-request script! It means that there is error in Pre-request script on Pre-request script tab in Postman – Roman Marusyk Mar 13 '20 at 15:44
  • 1
    Had commented on you mixing Query and Url parameters, but as @RomanMarusyk pointed out that isn't your current issue. Something to be aware of though – Tyler Hundley Mar 13 '20 at 15:45
  • I have word Name in my Pre Requet script. I am not sure where it came from. I removed Name from the preRequest script and put this instead: RecStartDate=01/01/2020 RecEndDate=01/02/2020. Now I am getting an error saying: Could not get any response There was an error connecting to https://localhost:44306/api/RecLoadPrime/insertRecLoadData/?RecStartDate=01/01/2020&RecEndDate=01/02/2020. – Anjali Mar 13 '20 at 15:45
  • If you need help, then show us your Pre-request script! How can we guess? – Roman Marusyk Mar 13 '20 at 15:47
  • I posted the image of pre request script. I also posted the new error that i am getting. The name error is gone after changing the preRequest script – Anjali Mar 13 '20 at 15:48
  • It sounds like you removed one value from pre request but then added another? Unless you have a use for it should be empty should it not? – Tyler Hundley Mar 13 '20 at 15:48
  • PreRequest is totally empty now. I started getting another error saying: – Anjali Mar 13 '20 at 15:53
  • I posted my error above – Anjali Mar 13 '20 at 15:56
  • Have you looked at the link provided in the error for troubleshooting steps? https://learn.microsoft.com/en-us/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-3.1#50030-in-process-startup-failure – Tyler Hundley Mar 13 '20 at 15:57
  • Make sure the program is running from visual studio, then in a new postman tab, only put in the URL i shared above. Also, try http instead of https. – Icculus018 Mar 13 '20 at 15:59
  • Thank You. I am trying all the things mentioned by you. – Anjali Mar 13 '20 at 16:09

1 Answers1

1

First, if you have [Route("api/[controller]")] then you don't need controller name (RecLoadPrime) here [Route("RecLoadPrime/insertRecLoadData/{RecStartDate}/{RecEndDate}")] because URL will be

https://localhost:44306/api/RecLoadPrime/RecLoadPrime/insertRecLoadData

Then, if it is POST request, it would be better to use request body with JSON instead route/query parameter. But it's up to you.

If you want to pass dates in URL then you have 2 options

  1. Use query string: [Route("RecLoadPrime/insertRecLoadData")] then URL will be http://localhost/api/RecLoadPrime/insertRecLoadData?RecStartDate=01/01/2020&RecEndDate=01/02/2020

  2. Use route parameters: [Route("RecLoadPrime/insertRecLoadData/{RecStartDate}/{RecEndDate}")] then you need to encode values before send http://localhost/api/RecLoadPrime/insertRecLoadData/01%2F01%2F2020/01%2F02%2F2020, and decode in controller.

See this answer to fix:

HTTP Error 500.30 - ANCM In-Process Start Failure

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116