2

I'm a newbie learner of ASP.NET. I was following along this ASP.NET Razor pages tutorial and deployed my app to Azure.

But when I'm trying to access this Movies page, I'm getting this error.

Error.

An error occurred while processing your request.

Request ID: | f9ecac03-478613f8cb88adc0.

Development Mode Swapping to the Development environment displays detailed information about the error that occurred.

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end-users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.

I've tried this existing solution and changed the mode to production but the problem remained the same.

Here is my launch setting -

{
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:50335",
      "sslPort": 44327
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    },
    "Polling_System": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    }
  }
}

My deployment mode was Framework-Dependent and later I changed it to Self-Contained.

Can anyone help me to resolve this problem? Thanks.

P.S. The page works properly on my machine if the value of "ASPNETCORE_ENVIRONMENT": is set to "Development"

Mahmudul Hasan
  • 798
  • 11
  • 35

1 Answers1

1

Update:

This is the stanard webconfig:

<?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=".\OurWebApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
     <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
  </aspNetCore>
  </system.webServer>
</configuration>

Solution:

Add or change the ASPNETCORE_ENVIRONMENT setting of your web.config.

As the error says,

The Development environment shouldn't be enabled for deployed applications.

So please change it to other env. I am sorry. Answered wrong just now.

Have look of this:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1#environments

Add these code in Web.config or change the value in webconfig.(under site/wwwroot on Kudu):

<environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="[Other env instead of Development]" />
</environmentVariables>

Your Kudu page should be: https://[yourwebsitename].scm.azurewebsites.net/DebugConsole

(Change the [yourwebsitename] to your website name and then you will go to kudu)

Don't forget to save the edit. This should work without restart.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Hi! I put the code int the web.config file. Unfortunately, it didn't work. Here is my web.config code - https://gist.github.com/MahmudX/b4e858b983051fbae520a1886e2efb99 – Mahmudul Hasan Jan 22 '20 at 08:16
  • @MahmudulHasan HI, MahmudulHasan . Why your file is `MahmudXwebConfiq.xml` instead of `Web.config`? – Cindy Pau Jan 22 '20 at 09:26
  • I just named my gist. – Mahmudul Hasan Jan 22 '20 at 10:57
  • @MahmudulHasan put the env between system.webServer. Have a look of my update answer. – Cindy Pau Jan 22 '20 at 11:01
  • Well, your answer fulfills my requirements. Now I can see the thrown exception. It's because of my app can't connect with the SQL server. I have no idea how to fix this problem. :( – Mahmudul Hasan Jan 22 '20 at 11:29
  • @MahmudulHasan You can create a new question and post the information about the question. You are welcome! – Cindy Pau Jan 22 '20 at 11:34
  • @MahmudulHasan And remember to add enough tags of the question. That will let others who know how to solve your problem see your question. – Cindy Pau Jan 22 '20 at 11:37