Publish ASP.NET v.Next to IIS

In this post I want to document the steps of publishing an ASP.NET v Next web site to IIS and have it successfully use an SQL Server database.  I am going to assume you downloaded the preview version of Visual Studio 2015 that allows you to create v. next projects. 

Start Visual Studio 2015 and create new project.  Pick ASP.NET Web Application project template under Web category in new project dialog.  You can now pick on the follow up dialog screen “ASP.NET 5 Preview Starter Web”.  This template creates a simple web site, that is using Entity Framework based ASP.NET Identity 2.0 template.  So, if we can get this to work completely inside IIS, my goal for this blog post would be satisfied.  Where is the database connection string?  It will be located inside config.json file at the root of the project inside the Visual Studio.  I will change the connection string to point to local SQL Server as you can see below.

“ConnectionString”: “Data Source=.;Initial Catalog=aspnet5;Integrated Security=SSPI;MultipleActiveResultSets=true”

This string points to local default instance of SQL Server (“.”).  It uses aspnet5 catalog and is using integrated security (SSPI).  Multiple active result settings is something that Entity Framework may use.

In the next step we will need to fix SQL Server to match the connection string.  If use user/password combination, you will need to create matching login with the appropriate rights.  Since I like integrated security in development, I want to pass identity from IIS into SQL Server.  To do so, we will give Application Pool Identity account some right inside SQL Server.  Open up SSMS, SQL Server Management Studio, add new login and type IIS AppPool\DefaultAppPool as windows account.  Create the account, then give it rights inside SQL Server by mapping it to sysadmin role.  You would not do this in production.  You would create a specific account.  However, if you use migrations, you mush have enough rights under that login to allow it to create the database.  So, let’s go with sysadmin for now.

Next step is to publish the application.  Right-click on project (not solution) node in Visual Studio and select publish.  You will see the following dialog.  Select “File System” option.

image

You will be prompted for profile name

image

Give it a name and lock OK.  On the next screen point to brand new folder.

 

image

 

On the next screen you can pick release or debug mode and run time.  Let’s go with defaults.

 

image

Finally, click publish on the review, last page of the wizard.

If you go to target folder C:\Users\Sergey\Documents\TestApp, you will see the artifacts of the publish process.   The root of the app is wwwroot folder under that folder.  Copy that path and head over to IIS Management Console in Control Panel –> Administrative Tools.  Right click on Default Web Site and choose Add  Application.  Give it an alias (virtual path) and paste in the proper folder.

image

Click OK.  This will link your new app to default app pool, preset with IIS install.  You need to give app pool identity proper right to published folder.  Go to security in windows explorer under TestApp folder.  Add Authenticated Users group account and give it read and execute rights.

Time to test.  Navigate to http://localhost/testing in a browser.  You should see the app come up.  Now head over to SQL Server and verify that identity tables got created in the database specified in the connection string.

That is all there is to.  Enjoy.