Aspnetcore.docs: Development Mode Error

Created on 12 Jul 2018  Â·  15Comments  Â·  Source: dotnet/AspNetCore.Docs

I followed this tutorial. It worked fine in the local host. When I deployed it in my azure website, I obviously changed the reply url to the public link. So I was able to select an account, enter password, and allow the permissions, but then I got this error:

An error occurred while processing your request.
Request ID: 0HLF7H4694HLM:00000006
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.

I changed the environment mode to Production in my App, same error. I'm starting to suspect it has to do with something else. Any help?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P2 Source - Docs.ms

Most helpful comment

Thank you for your quick response, Rick. This link did not have the answer, however, I was able to solve it. Turns out, when you deploy your web app, you must go to the appsettings.json file, and replace the "DefaultConnection" from "ConnectionStrings" with a server key generated in azure or some other database service. Indeed the log is misleading, since when the app is deployed, it is in Production mode, but the debugger notes a local default connection string, so it gets confused and assumes it is in Development mode instead.

This tutorial is very complete, but I strongly recommend the writers to include this key piece of information, since it is essential for deploying the app.

All 15 comments

See https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.1

And try setting the ASPNETCORE_ENVIRONMENT environment variable to Development,

Thank you for your quick response, Rick. This link did not have the answer, however, I was able to solve it. Turns out, when you deploy your web app, you must go to the appsettings.json file, and replace the "DefaultConnection" from "ConnectionStrings" with a server key generated in azure or some other database service. Indeed the log is misleading, since when the app is deployed, it is in Production mode, but the debugger notes a local default connection string, so it gets confused and assumes it is in Development mode instead.

This tutorial is very complete, but I strongly recommend the writers to include this key piece of information, since it is essential for deploying the app.

Hello,
When I paste the following code in the Startup, I get an error on ApplicationUser. It says the type or namespace ApplicationUser could not be found or you are missing an assembly reference. I was wondering if know why?
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();

Hi, I think your solution "...appsettings.json file, and replace the "DefaultConnection" from "ConnectionStrings" with a server key generated in azure..." could really help me. Would you be able to give me some more information about where you found the server key generated in Azure please - and also the syntax you used in the JSON file? Would really appreciate your help. Cheers

you must go to the appsettings.json file, and replace the "DefaultConnection" from "ConnectionStrings" with a server key generated in azure or some other database service

That's the wrong approach. See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2#providers

Thank you so much!

On Wed, Jan 9, 2019 at 12:03 AM Rick Anderson notifications@github.com
wrote:

you must go to the appsettings.json file, and replace the
"DefaultConnection" from "ConnectionStrings" with a server key generated in
azure or some other database service

That's the wrong approach. See
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2#providers

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/aspnet/Docs/issues/7581#issuecomment-452572949, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABsl_ocItyTQAtsO_SpnlU-L93qSDBd8ks5vBXgfgaJpZM4VMB8S
.

Hi Dona, I having the same issue. I put the right serve connection string in my appsetting.json file but still getting the same error. can you please help me out with this.

deploy to IIS not azure, getting the same error, anything else?

had the same issue, turned out to be the this call
//.AddValidationKeyFromFile(Configuration.GetSection("SigninKeyCredentials"), _loggerFactory.CreateLogger())

that caused the trouble. use the developersigningcredentials seems to work fine.

I think this will help
all you need is to display the real error by adding these lines in startup:

app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();

without the condition of if (env.IsDevelopment())

and remove these lines if exists

app.UseExceptionHandler("/Error");
app.UseHsts();

then just let the app displaying the error like in development mode so you can search about it and fix it

after you fix the error(s) you can remove these changes so users can not see the error :)

This tutorial is very complete, but I strongly recommend the writers to include this key piece of information, since it is essential for deploying the app.

Can you please help me how to find the server key generated in Azure? urgent need

This has nothing to do with Azure deployment. That's a different article.

i face same problem in 3.1 . any one help me?

I think this will help
all you need is to display the real error by adding these lines in startup:

app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();

without the condition of if (env.IsDevelopment())

and remove these lines if exists

app.UseExceptionHandler("/Error");
app.UseHsts();

then just let the app displaying the error like in development mode so you can search about it and fix it

after you fix the error(s) you can remove these changes so users can not see the error :)

@abdullah-alimam, Your solution helped me a lot.

Here's how my I solved my problem:

I had the same problem (ASP.NET CORE 3.1) but changing "ASPNETCORE_ENVIRONMENT" did not helped.

Seeing @abdullah-alimam 's answer, I found that in Startup.cs, Configure method, this code was hiding the real issue.

 if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

Then I deleted the If block and added Database error pages ( You might need to Install Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore from NuGet )

app.UseDatabserrorPages();

So your Startup.cs will look like this

app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();

app.UseHttpsRedirection();

//Others will be Okay

Then you will see the real errors on the webpage. For me it was

Login failed for user IIS APPPOOL\DefaultAppPool

So I had to run a GRANT SCRIPT. I just had to run this script on my SQL Server

IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOL\DefaultAppPool')
BEGIN
    CREATE LOGIN [IIS APPPOOL\DefaultAppPool] 
      FROM WINDOWS WITH DEFAULT_DATABASE=[master], 
      DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [WebDatabaseUser] 
  FOR LOGIN [IIS APPPOOL\DefaultAppPool]
GO
EXEC sp_addrolemember 'db_owner', 'WebDatabaseUser'
GO

You can see this link : https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis

And my problem was solved. Hope this helps somebody.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

royshouvik picture royshouvik  Â·  3Comments

StevenTCramer picture StevenTCramer  Â·  3Comments

wgutierrezr picture wgutierrezr  Â·  3Comments

madelson picture madelson  Â·  3Comments

sonichanxiao picture sonichanxiao  Â·  3Comments