ASP.NET azure hosted app / sql server Works on localhost only

Anel Hodžić 0 Reputation points
2024-06-11T20:15:24.4333333+00:00

When I run my simple CRUD app on localhost it works really good.

Hint: It is using SQL server to insert data and server is hosted on my Azure Subscription inside same Resource Group

Deployed app : myAzureWebsitesLink.net

Not working route : School - Region - Countries

/Countries/CountriesIndex

On Azure SQL Server - Networking this is my props

User's image

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "AZURE_SQL_CONNECTIONSTRING": "Server=tcp....database.windows.net,1433;Initial Catalog=myDB;Persist Security Info=False;User ID=myUser;Password=myPW;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=120;"
  }


CountriesController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Models;

namespace Controllers
{
    public class CountriesController : Controller
    {
        private readonly ApplicationDbContext _context;

        public CountriesController(ApplicationDbContext context)
        {
            _context = context;
        }

        // GET: Products
        public async Task
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,611 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,507 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
966 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anel Hodžić 0 Reputation points
    2024-06-14T19:59:30.3166667+00:00

    Detailed log was found at this path :

    User's image

    Keep in mind that your appsettings.json file was not deployed

    You need to add SqlConnection string in your app with prefix as explained : Configure Connection Strings


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.