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

好久不见. 提交于 2020-08-10 01:14:30

问题


As per the postman or web to check API as in the local environment it works. But as I update my launchSettings.json with "ASPNETCORE_ENVIRONMENT": "Production" from "Development" in two places as per the image location path below.

And added in configuration setting new application setting of Azure Application Settings as per research over the websites.
Here are some websites which i referred to for solutions.

  1. https://github.com/MicrosoftDocs/azure-docs/issues/29976
  2. How and where to define an environment variable on Azure
  3. ASP.NET Core deployment to IIS error: Development environment should not be enabled in deployed applications

Still, it shows me error on postman when I check Web API after hitting the URL.

<div class="container">
            <main role="main" class="pb-3">
                <h1 class="text-danger">Error.</h1>
                <h2 class="text-danger">An error occurred while processing your request.</h2>
                <p>
                    <strong>Request ID:</strong>
                    <code>|14a7ad86-47801a7069301d42.</code>
                </p>
                <h3>Development Mode</h3>
                <p>
    Swapping to 
                    <strong>Development</strong> environment will display more detailed information about the error that occurred.
                </p>
                <p>
                    <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
    It can result in displaying sensitive information from exceptions to end users.
    For local debugging, enable the
                    <strong>Development</strong> environment by setting the
                    <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to
                    <strong>Development</strong>
    and restarting the app.
                </p>
            </main>
        </div>

Update 1:-
This Url for Web Api is working.
https://kerisuiteapp.azurewebsites.net/Staff/StaffTest
Here is my code which i used.

    [AllowAnonymous]
    [HttpGet("StaffTest")]
    public IActionResult StaffTest()
    {
        var test = new { name = "joy", number = "123123123", Fax = "234234" 
                       };
        return Json(test);
    }

But this shows me error.
https://kerisuiteapp.azurewebsites.net/Staff/GetStaff
Here is the code which is not working on Azure.

    [AllowAnonymous]
            [HttpGet("GetStaff")]
            public IActionResult Staff()
            {
                try
                {
                    var staffModel = _StaffService.GetStaff();
    
                    return Ok(staffModel);
                }
                catch (Exception ex)
                {
                    return Json(ex);
                }
            }

public List<Staff> GetStaff(){
            return uow.Repository<Staff>().Get();
        }

回答1:


I think your problem is likely to be a database connection error. Because I guess your program must be normal in the offline test environment before deployment, so the code level is temporarily ignored.

If you are using Azure SQL DB, your connection string should look like the following.

Data Source=tcp:servername.database.windows.net,1433;Initial Catalog=db;
Persist Security Info=False;
User ID=user;Password=mypassword;
MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;
Connection Timeout=30;

If you are using SQL Server in a virtual machine or physical server, your connection string should look like this.

<connectionStrings>
<add name="DefaultConnection11" connectionString="Data Source =111.111.111.111;Initial Catalog = {your db in server not azure};User Id = {userid};Password ={password};" />
</connectionStrings>

For more details, you can refer my answer in this post.

If you are sure that there is no problem with the database connection, it is recommended to use remote debugging to troubleshoot errors.



来源:https://stackoverflow.com/questions/63197229/the-development-environment-shouldnt-be-enabled-for-deployed-applications-dotn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!