2

I've developed an ASP.NET WebApi application. When I publish and test it to localhost IIS,I got this error at one request:

   Response with status: 500 Internal Server Error for URL: 
http://localhost/api/COMI/NEW/158/3

web.config:

      <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <system.webServer>
            <handlers>
              <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
    resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath="dotnet" arguments=".\POSweb.dll" 
stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
          </system.webServer>
        </configuration>
        <!--ProjectGuid: 5f28b9b3-0e00-439a-8fa1-e64186505b5e-->

Running it for IDE gives no error at that point.How can I fix/debug this.

route configuration:

 app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });

thanks

mrapi
  • 5,831
  • 8
  • 37
  • 57
  • 1
    what was the URL that produced this error? – DaniDev Nov 02 '17 at 16:06
  • Hi.I've added it to first post.thanks – mrapi Nov 02 '17 at 16:08
  • 2
    If you published it to your local IIS server you probably created webApp for it under the default website? If so your path should include that. Probably something like: http://localhost/Myapiapp/api/COMI/NEW/158/3 – DaniDev Nov 02 '17 at 16:16
  • Hi.I've created a new site.application loads but one request fails,other works – mrapi Nov 02 '17 at 16:28
  • Are you saying that you just did this and now just one request fails or is the one you mentioned above that failed earlier. – DaniDev Nov 02 '17 at 16:35
  • 1
    Not sure if I follow... title states "only on production" and example in description is about localhost ... ? Anyhow, if you want to learn more about this (random?) error, start with added logging. Eg by setting stdoutLogEnabled to true. See also https://learn.microsoft.com/en-us/aspnet/core/hosting/aspnet-core-module#configuration-via-webconfig – AardVark71 Nov 02 '17 at 16:39
  • @Dani: no.I've done nothing after your first answer – mrapi Nov 02 '17 at 16:39
  • It would seem to me that what ever generated that request is not routing correctly ? Does it match what you have configured? – DaniDev Nov 02 '17 at 16:42
  • @ Aard In my sources project I don't have a web.config file,only on deploy.Thare shoul I put stdoutLogEnabled=false? – mrapi Nov 02 '17 at 16:43
  • @Dani: I've added route config to first post. – mrapi Nov 02 '17 at 16:45
  • 1
    you probably also a route registered for the API calls something like: routeTemplate: "api/{controller}/{id}", can you post one URL that does not give an error? Can you show what is making this bad request? – DaniDev Nov 02 '17 at 16:52
  • that works: http://localhost/api/COMI/OPENED and that not: http://localhost/api/COMI/NEW/158/3 – mrapi Nov 02 '17 at 16:55
  • simply accessing the link in browser gives error (there are GET requests,not secured) – mrapi Nov 02 '17 at 17:47
  • Have you installed the .Net core framework in target server? – Kalyan Nov 02 '17 at 22:42
  • Hi.Target machine is the development machine,for production testing – mrapi Nov 03 '17 at 06:34
  • I've solved using TryParseExact just like [there](https://stackoverflow.com/questions/18494124/datetime-problems-when-moving-to-production-environment/18494239#18494239): – mrapi Dec 12 '18 at 12:52
  • I've solved using TryParseExact just like [there](https://stackoverflow.com/questions/18494124/datetime-problems-when-moving-to-production-environment/18494239#18494239) – mrapi Dec 12 '18 at 12:55

2 Answers2

1

You need to enable stdoutlogenabled and create a log directory in your root to get the aspnet core logs to troubleshoot the actual error ... more info here https://stackoverflow.com/a/35712042/1137785

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>
Muqeet Khan
  • 2,094
  • 1
  • 18
  • 28
  • I have no web.config in my project.only when I publish there is.should I put it there every time?.thanks – mrapi Nov 02 '17 at 16:48
  • There should be a web.config in the root of your project. If not, you can make one and put the web.config content I have in the answer now. You could modify the production web.config (will need admin access) but you shouldn't have to, also remember, when `you change web.config, IIS will do an app pool recycle`. – Muqeet Khan Nov 02 '17 at 17:01
  • I've put stdoutLogEnabled="true" in web.config but found no log ..I have in wwwroot \logs\stdout folder – mrapi Nov 02 '17 at 17:09
  • make sure you have created a directory named `logs` in the root of your application. – Muqeet Khan Nov 02 '17 at 17:20
  • yes.that I've said before: I have wwwroot\logs\stdout folder – mrapi Nov 02 '17 at 17:21
  • 1
    `stdoutLogFile=".\logs\stdout"` is the path its trying to put the logs in. Notice that there is no `wwwroot` in that path. You need to make the logs folder 1 level above from where you have it now. – Muqeet Khan Nov 02 '17 at 17:23
  • My site is located to C:\inetpub\PublishOutput. Inside I have wwwroot, ClientApp, logs\stdout folders.But no file found in logs\stdout – mrapi Nov 02 '17 at 17:28
  • Debugging step by step seems that in production mode this conversion DateTime.Parse('25/09/2017'); is the problem.but only in production.I don't have exact error message because I can't get it – mrapi Nov 02 '17 at 18:30
  • I've solved using TryParseExact just like this problem: https://stackoverflow.com/questions/18494124/datetime-problems-when-moving-to-production-environment/18494239#18494239 Thanks all of you! – mrapi Nov 03 '17 at 13:26
0

I've solved using TryParseExact like there

mrapi
  • 5,831
  • 8
  • 37
  • 57