skip to Main Content

I have the following code in the StartUp.ConfigureServices

  services.AddCors(c=>c.AddPolicy(Konstants.CORS, d=>
                    d.AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()
                        .AllowCredentials()
                    )
                );

and in the Configure method I use the following as the first line:

app.UseCors(Konstants.CORS);

On every controller for web api I use the following

 [Route("api/[controller]")]
    [EnableCors(Konstants.CORS)]
    [ApiController, Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    [Consumes("application/json"), Produces("application/json")]
    public class EmployeesController : ApiBaseController
    {

On local machines everything runs fine. But on remote machine i.e. the production one, HTTPGet works fine but for all HTTPPOST it returns 404.

here is my web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".myapp.Web.exe" stdoutLogEnabled="true" stdoutLogFile=".logsstdout" />
    </system.webServer>
  </location>
</configuration>

What could be the issue? I have access to webserver through plesk.
A few details I missed. This website has regular controllers as well as API controllers hosted in the same app. for api controller we use JWTToken for other controllers we use cookies. Website works just fine. Api controllers have all Get Requests work fine and they even fetch the data from database correctly (so at least its not a DB issue) but all api POST return 404. URL not found.

As @Anton asked, here is one of the post request

[HttpPost("Start")]
        public async Task<IActionResult> StartJob([FromBody] JobActivityModel model)
        {
            var ret = Empty;

            try
            {

                await Execute(new StartJob
                {
                    JobId = model.JobId,
                    PersonId = UserId,
                    At = model.CreatedAt
                });

                Log.Info($"{SoligoUser} has started the job");

                ret = Ok(new TimeClue
                {
                    Message = "job has been started",
                    IsSuccess = true,
                    Time = model.CreatedAt
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ret = Error(ex);
            }

            return ret;
        }

2

Answers


  1. Chosen as BEST ANSWER

    After much time wasted on web searches this turned out to be the solution:

    enter image description here

    Adding this line solved all the issues. Post is now working correctly and sometimes the Media Not Supported Error was encountered was also fixed.

    I wish someday the compiler will tell "hey, you need to put this"


  2. You may try below things.

    1. Install swagger and try
    2. RDP in to server and try to run on server. This will give exact error.
    3. Check headers of post request you tried with server.
    4. Double check paths and payloads are correct
    5. Follow this to host .net core in iis.
    6. Check you are sending correct tokens to server
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search