ASP.NET Web Deployment Using Visual Studio Tom Dykstra
Total Page:16
File Type:pdf, Size:1020Kb
ASP.NET Web Deployment using Visual Studio Tom Dykstra Summary: This tutorial series shows you how to deploy (publish) an ASP.NET web application to a Windows Azure Web Site or a third-party hosting provider, by using Visual Studio 2012 or Visual Studio 2010. You develop a web application in order to make it available to people over the Internet. But web programming tutorials typically stop right after they've shown you how to get something working on your development computer. This tutorial begins where the others leave off: you've built a web site, tested it, and it's ready to go. What's next? This tutorial shows you how to deploy first to IIS on your local development computer for testing, and then to Windows Azure or a third- party hosting provider for staging and production. The sample application that you'll deploy is a web application project that uses the Entity Framework, SQL Server, and the ASP.NET membership system. The sample application uses ASP.NET Web Forms, but the procedures shown apply also to ASP.NET MVC and Web API. Category: Step-by-Step Applies to: ASP.NET, Visual Studio 2010, Visual Studio 2012, Windows Azure Source: ASP.NET Site (http://asp.net/web-forms/tutorials/deployment/visual-studio- web-deployment/introduction) E-book publication date: April, 2013 Copyright © 2013 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. ASP.NET Web Deployment using Visual Studio Contents Introduction .................................................................................................................................................. 6 Overview ................................................................................................................................................... 6 Intended audience .................................................................................................................................... 6 Using a third-party hosting provider ......................................................................................................... 7 Deploying web site projects ...................................................................................................................... 7 Deploying ASP.NET MVC projects ............................................................................................................. 7 Programming language ............................................................................................................................. 7 Database deployment methods................................................................................................................ 7 Entity Framework Code First Migrations .............................................................................................. 8 The dbDacFx Web Deploy provider ...................................................................................................... 8 Troubleshooting during this tutorial ......................................................................................................... 9 Comments welcome ................................................................................................................................. 9 Prerequisites ............................................................................................................................................. 9 Download the sample application .......................................................................................................... 10 Review application features that affect deployment ............................................................................. 13 Summary ................................................................................................................................................. 14 Preparing for Database Deployment .......................................................................................................... 15 Overview ................................................................................................................................................. 15 SQL Server Express LocalDB .................................................................................................................... 15 Entity Framework and Universal Providers ............................................................................................ 15 Configure Code First Migrations for application database deployment ................................................ 16 Disable the initializer ........................................................................................................................... 18 Enable Code First Migrations .............................................................................................................. 18 Set up the Seed method ..................................................................................................................... 20 Create scripts for membership database deployment ........................................................................... 23 Summary ................................................................................................................................................. 33 More Information ................................................................................................................................... 34 1 Web.config File Transformations ................................................................................................................ 35 Overview ................................................................................................................................................. 35 Web.config transformations versus Web Deploy parameters ............................................................... 35 Default transformation files .................................................................................................................... 35 Disable debug mode ............................................................................................................................... 36 Limit error log access to administrators ................................................................................................. 37 A setting that you'll handle in publish profile transformation files ........................................................ 42 Setting connection strings ...................................................................................................................... 43 Summary ................................................................................................................................................. 43 More Information ................................................................................................................................... 44 Project Properties ....................................................................................................................................... 45 Overview ................................................................................................................................................. 45 Configure deployment settings in the project properties window ........................................................ 45 Make sure that the Elmah folder gets deployed .................................................................................... 47 Summary ................................................................................................................................................. 48 Deploying to Test ........................................................................................................................................ 49 Overview ................................................................................................................................................. 49 Install IIS .................................................................................................................................................. 49 Install SQL Server Express ....................................................................................................................... 53 Create SQL Server Express databases for the test environment ............................................................ 53 Create a grant script for the new databases........................................................................................... 55 Run the grant script in the application database .................................................................................... 56 Publish