23

After publishing an ASP.NET Web App, I'm trying to host the website on my local server. However, when I start it up, it gives me this error in my browser:

Oops. 500 Internal Server Error An error occurred while starting the application.

How can I debug what this error is? The website works (both Debug and Release configurations) when starting using IISExpress and "web" in Visual Studio.

I am using the Development environment, and I have already specified app.UseDeveloperExceptionPage();.

I have followed the instructions here to deploy to IIS.

I've also tried the suggestion offered here (re-publishing with "Delete all existing files prior to publish" selected). (The OP there has a slightly different error, so that's why I'm posting a new question.)

I've looked for hours on the internet, but there doesn't seem to be much content about it. Any ideas?

I am on Windows 7, using ASP.NET 5 RC1.

Community
  • 1
  • 1
painiyff
  • 2,519
  • 6
  • 21
  • 29
  • 2
    Enable httpPlatform stdout logs in web.cnfig to see the actual error in the log file. I had the error because my DB permissions were not set properly and I was using integrated security :-) – Muqeet Khan Feb 27 '16 at 03:32
  • 1
    @MuqeetKhan Lmao I did this and apparently the exception was relating to not being able to find a configuration file. OOPS. The website uses the configuration file based on the Hosting Environment. I didn't know the "Publish" tool changed the Hosting Environment to Production. I just assumed it was still Development... – painiyff Feb 29 '16 at 21:52
  • 1
    Glad it helped. Could you accept the answer when you have a chance. Thanks ! – Muqeet Khan Feb 29 '16 at 23:49

5 Answers5

38

You should set the stdoutLogEnabled=true in the web.config file to see the actual error that is happening. You can direct where these files are written with the stdoutLogFile argument; the screenshot example below writes to stdoutLogFile=".\logs\stdout". (You should ensure the directory exists; the app won't create it)

As for not being able to find the proper config file yes the default environment is production. It is set to development explicitly in visual studio in the project properties.

Update: In AspNetCore RTM the module is called aspnetCore under the system.webServer node in web.config. Also, as @ErikE pointed out in comments, the web.config is now located in the root of the project and not under wwwroot as in previous releases.

enter image description here

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
Muqeet Khan
  • 2,094
  • 1
  • 18
  • 28
  • 1
    Can you tell me where in the Web.config this option is set? – Paul Cavacas Apr 25 '16 at 12:41
  • 3
    in the wwwroot folder the web.config will contain the section httpPlatform. This section will have the stdoutLogEnabled attribute. It's default value is false, change it to true. Restart the web pool after you do this and it throws an error make sure kill all instances of w3wp.exe and dnx.exe in task mgr. – Muqeet Khan Apr 25 '16 at 16:45
  • `web.config` is now published to the parent folder of `wwwroot`, so look for it in the right place! – ErikE Aug 29 '16 at 08:42
  • 3
  • It is "stdoutLogEnabled" – Skorunka František Dec 11 '16 at 17:35
  • 5
    One more tip that might be good to include in the answer, the aspNetCore element in the web.config file also contains a "stdoutLogFile" attribute which specifies the folder where the logs will be written. If this folder doesn't already exist, IIS won't create it for you (which was a bit confusing to me... I was wondering why I wasn't getting any logs even though I had stdoutLogEnabled="true"). – James Crosswell Jan 27 '17 at 17:55
  • @JamesCrosswell - thanks. There is also another catch - you need your app to have permissions for that folder. Refer here https://stackoverflow.com/questions/14934006/iis-iusrs-and-iusr-permissions-in-iis8 – statler Oct 17 '17 at 03:02
8

This error also occurs when you are attempting a database connection from the startup (eg for seeding) and it fails on the deployment server due to insufficent previleges at the database server.

Andre
  • 131
  • 1
  • 5
2

This error occurs under several conditions. In my situation, I did not have the database connection string set correctly. I fixed it in Visual Studio 2017 as follows:

1) Right-click project, select Publish, open the Publish page in main area.

2) Select the Publish tab on the left

3) Under Summary section, there's a "Settings..." link. Click it. This opens the Publish dialog.

4) Click Settings tab on the left.

5) Expand File Publish Options, check "Remove additional files at destination"

6) Expand Databases, check "Use this connection string at runtime" (This was pre-populated with my Azure SQL connection string based on how I originally set up my publish options)

7) Expand Entity Framework Migrations, check "Apply this migration on publish" (Again, connection string was pre-populated)

8) Click Save

9) Publish

10) Cross your fingers

Bob Tabor
  • 967
  • 1
  • 13
  • 23
1

I was getting same issue. Checked the log and found that, inside config.json => HostConfig FileUpload path (pointing local drive) was incorrect. and creating problem to restart application. Conclusions: there might be multiple reason for this issue.

0

The Problem: most likely this error is due to insufficient privileges for the Application Pool Identities. To find out:

Go to windows Task Manager and under Details tab / Processes (Depending on Windows OS) look for w3wp.exe and under User name look for your application (<App_Pool_Name> usually DefaultAppPool) running there as an IIS Worker Process. If your app is not listed there, then the App has insufficient privileges with your database.

To Fix it: do the following and give full access to your App:

Go to your SQL Server Management Studio and Login as Administrator open Security > Logins > right click Logins and add a New Login:

Under General:

  • for Login Name: Enter IIS APPPOOL\<App_Pool_Name> usually DefaultAppPool

  • for Default Database: point to <Your_App_Database>

Under User Mapping:

  • on the box Users mapped to this login:

    -Check the box to Map to <Your_App_Database>

    -Under user Enter IIS APPPOOL\<App_Pool_Name>usually DefaultAppPool

    -Under Default Schema Enter dbo

  • on the box Database role membership for: <Your_App_Database>

    -Check the following boxes: db_datareader, db_datawriter, and public

Click OK

Now try to access your App and it should work!!!

Jacman
  • 1,486
  • 3
  • 20
  • 32