Giter VIP home page Giter VIP logo

dotnetcore-sqldb-tutorial's Introduction

languages page_type description products
csharp
aspx-csharp
sample
This is a sample application you can use to follow along w/ the Build a .NET Core and SQL Database web app in Azure Web Apps for Containers tutorial.
azure
aspnet-core
azure-app-service

.NET Core MVC sample for Azure App Service

This is a sample application that you can use to follow along with the tutorial at Build a .NET Core and SQL Database web app in Azure Web Apps for Containers.

License

See LICENSE.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Additional SQL Configuration for Managed Identities

  1. Modify SQL Server Firewall
    • Add Web Server IP Address (or just enable Azure Services Access)
  2. Enable Managed Identity on WebApp
    • Note the name of the WebApp
  3. Grant the WebApp Access to to the database in the query editor (or SSMS)
CREATE USER [WebAppName] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [WebAppName];
ALTER ROLE db_datawriter ADD MEMBER [WebAppName];
  1. Add packages to the project dotnet add package
    • Azure.Identity
    • System.Data.SqlClient
  2. Update startup.cs in the ConfigureServices method
var connString = Configuration.GetConnectionString("MyDbConnection"); //Just need Server and Database/Initial Catalog in the conn string now
// Create a new connection
var sqlConn = new System.Data.SqlClient.SqlConnection(connString);
// Get the AD credential context for the application
var credential = new DefaultAzureCredential();
//get a token with the current app's context
var token = credential.GetToken(new Azure.Core.TokenRequestContext(new[] {"https://database.windows.net/.default"}));
// Add the token obtained to the connection to OAuth enable it
sqlConn.AccessToken = token.Token;

services.AddDbContext<MyDatabaseContext>(options =>
    options.UseSqlServer(sqlConn)); //pass the connection now, not the connection string

dotnetcore-sqldb-tutorial's People

Contributors

cephalin avatar joelbyford avatar microsoftopensource avatar msftgits avatar spboyer avatar

Watchers

 avatar

Forkers

msftsean

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.