Build ASP.NET Applications for Windows Server...

27
Windows Server 2008 R2 Developer Lab Series Server Core .NET Applications Lab version: 1.0.0 Last updated: 4/3/2022

Transcript of Build ASP.NET Applications for Windows Server...

Page 1: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Lab SeriesServer Core .NET ApplicationsLab version: 1.0.0Last updated: 5/18/2023

Page 2: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Contents

Abstract.......................................................................................................................................................3

Related MSDN Channel9 Webcasts.............................................................................................................3

Related MSDN Code Gallery Projects..........................................................................................................3

Scenario.......................................................................................................................................................3

Exercise 1: Configure ASP.NET on Server Core............................................................................................4

Part 1: Server Core Optional Features..................................................................................................5

Part 2: Install the IIS Management Services.........................................................................................6

Exercise 2: Configure Your Web Application...............................................................................................7

Part 1: Add the New Web Site............................................................................................................10

Part 2: Add the New Web Application................................................................................................11

Part 3: Enable Anonymous User Authentication................................................................................11

Part 4: Browse to the New Web Application......................................................................................12

Exercise 3: Debug ASP.Net Applications on Server Core............................................................................13

Part 1: Deploying the remote debugger service.................................................................................13

Part 2: Setting-up the Visual Studio Machine.....................................................................................14

Hardware Requirements...........................................................................................................................18

Appendix A: Host Machine Configuration.................................................................................................18

Hardware Requirements........................................................................................................................18

Virtualization Host Configuration...........................................................................................................19

Appendix B: R2 Developer VM Configuration............................................................................................19

Software Requirements.........................................................................................................................19

Operating System...................................................................................................................................19

Developer Tools (install these as “full installations”).............................................................................19

Network Configuration..........................................................................................................................20

Appendix C : R2 Server Core VM Configuration.........................................................................................20

Virtual Machine Configuration...............................................................................................................20

General Setup........................................................................................................................................20

Page 3: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Abstract

With Windows Server 2008 R2, the Server Core installation option introduces support for .NET applications including ASP.NET.

In this hands-on-lab, we discuss how to install the optional roles and features that enable IIS and ASP.NET on Server Core. We also provide guidance on remote management and debugging of ASP.NET applications hosted via Server Core.

This documentation is maintained at the following MSDN Code Gallery page: http://code.msdn.microsoft.com/r2coreaspnet

Related MSDN Channel9 Webcasts

http://channel9.msdn.com/posts/philpenn/How-to-Deploy-ASPNET-Applications-on-Server-Corehttp://channel9.msdn.com/posts/philpenn/How-To-Debug-ASPNET-Applications-on-Server-Core

Related MSDN Code Gallery Projects

http://code.msdn.microsoft.com/R2CoreAppshttp://code.msdn.microsoft.com/r2corehttp://code.msdn.microsoft.com/W2K8R2

Scenario

This lab requires two preconfigured servers configured as Virtual Machines within a Hyper-V virtualization environment as illustrated below. Machine names, accounts, and IP configuration details follow. Refer to the appendices herein for detailed machine configuration procedures.

Page 4: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 1

◦ Host 1: Win2K8R2Dev, IP=10.0.0.1

◦ Host 2: Win2K8R2Core, IP=10.0.0.3

◦ User 1: Administrator, p@ssw0rd

◦ User 2: student1, p@ssw0rd

Exercise 1: Configure ASP.NET on Server Core

Windows Server 2008 R2 Server Core includes subsets of the 2.0/3.0/3.5 .NET Framework. The Framework makes it possible to run an almost full-featured version of ASP.NET. However, there are specific limitations that you should take into consideration when working with ASP.NET on Server Core.

No MMC Snap-in. To configure, host, and manage Server Core hosted ASP.NET websites, you must do so via a remote connection from an IIS Management Console (i.e. MMC snap-in) running on a client computer. You can also manage practically every aspect of IIS sites and applications via a local administrative command console using the command line utility APPCMD.

No System.Web.Mail Namespace. The namespace System.Web.Mail is not supported because CDOSYS is not present on Server Core. The System.Web.Mail namespace was deprecated some time ago, so

Page 5: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

chances are that your code is no longer using them anyway. Use System.Net.Mail instead as it offers the same functionality.

The Web Application Tool (WAT) is not available on Windows Server 2008 R2 Core.

Part 1: Server Core Optional Features

1. Locate the Hyper-V management console on your hands-on-labs host machine. Open the virtual machine console onto the Win2K8R2Core virtual machine.

2. Logon to the provided Server Core machine, Win2K8R2Core, using account student1.

3. At the command prompt, type the following command to see a list of enabled/disabled optional features:

dism /online /get-features /format:table

Note: Note that the Deployment Image Servicing and Management (DISM) utility is the primary feature management tool for modifying Server Core installations.

4. Use the following command to determine more precisely the status of ASP.NET feature configuration.

dism /online /get-features /format:table | find /I “ASP”

Note: Note the resultant error message when attempting to install the ASP.NET feature without first installing dependent features.

5. DISM provides a list of additional features that must first be enabled.

dism /online /enable-feature /featurename:IIS-ASPNET

6. Before installing the Web Server Role, IIS and dependencies, we must make sure that the .NET Framework is installed. To install the 2.0/3.0 .NET Framework, use the Deployment Image Servicing and Management (DISM) utility as follows. NOTE that the featurename field is case sensitive and must be typed exactly as illustrated.

dism /online /enable-feature /featurename:NetFx2-ServerCore

dism /online /enable-feature /featurename:NetFx3-ServerCore

Page 6: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

7. The optional server role that must be configured to enable ASP.NET on IIS 7 is called IIS-ASPNET. This role has various pre-requisites that must first be installed. The first one is the Web Server Role, which can be enabled via following command:

dism /online /enable-feature /featurename:IIS-WebServerRole

Note: Once you have enabled the IIS-WebServerRole, three additional roles must be installed prior to the installation of the IIS-ASPNET role:

◦ IIS-ISAPIFilter

◦ IIS-ISAPIExtensions

◦ IIS-NetFxExtensibility

8. These roles are installed by issuing the following commands (in corresponding order):

dism /online /enable-feature /featurename:IIS-ISAPIFilterdism /online /enable-feature /featurename:IIS-ISAPIExtensionsdism /online /enable-feature /featurename:IIS-NetFxExtensibility

9. Now, install the IIS-ASPNET optional feature using the following command:

dism /online /enable-feature /featurename:IIS-ASPNET

10. Determine if the IIS service is running via the following command:

sc query w3svc

Part 2: Install the IIS Management Services

At this point, your Server Core machine is capable of hosting ASP.Net applications. However, on Server Core, there is no IIS management console and no service running that may be leveraged from a remote management console. This means that if you want to create web sites and web applications, you would have two options. Either use appcmd.exe, a command line utility found within the Windows system folder, or, enable the IIS Management Service and use an IIS Management Console from a remote client machine.

1. Let's choose the remote management console option and install the IIS Management Service as follows.

dism /online /enable-feature /featurename:IIS-ManagementService

2. You must also install the WAS-WindowsActivationService and the WAS-ConfigurationAPI as follows:

Page 7: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

dism /online /enable-feature /featurename:WAS-WindowsActivationServicedism /online /enable-feature /featurename:WAS-ConfigurationAPI

3. Once installed, you must do some registry hacking in order to enable the service. The following command will set a registry key value that allows the remote management service to be started:

Reg Add HKLM\Software\Microsoft\WebManagement\Server /V EnableRemoteManagement /T REG_DWORD /D 1

4. Although now enabled, the IIS Management Service is currently "stopped". Set the service to "started" using the following command:

net start wmsvc

5. Confirm that the management service is running using the following command:

sc query wmsvc

Exercise 2: Configure Your Web Application

A first step in website configuration is to create folders and copy the application files onto the Server Core web server.

1. Use the following commands to copy the test web application from the Win2K8R2Dev machine:

mkdir c:\inetpub\testmkdir c:\inetpub\test\websitexcopy \\10.0.0.1\SCRATCH\website\*.* c:\inetpub\test\website\*.* /S

2. Also enable TCP Port 81 as we will access this website as http://10.0.0.3:81/website. This procedure may also be accomplished from a remote client machine using the MMC add-in “Windows Firewall with Advanced Security”.

Netsh advfirewall firewall add rule name=”Port81” dir=in action=allow protocol=TCP localport=81

Page 8: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

3. Locate the Hyper-V management console on your hands-on-labs host machine. Open the virtual machine console onto the Win2K8R2Dev virtual machine.

Note: The screen-capture graphics herein may differ slightly from your physical lab experience.

4. Logon to the virtual machine, Win2K8R2Dev, using account student1.

5. Once your Server Core machine has been configured to allow the remote management, connect remotely by starting the IIS Management Console via the Start-AdministrativeTools menu. Select the option to "Connect to a Server…" as follows:

Figure 2

6. On the first subsequent screen, enter the name of the Server you wish to connect to Win2K8R2Core (i.e. 10.0.0.3):

Page 9: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 3

7. The next screen will ask for your user credentials on the remote server (i.e. student1, p@ssw0rd):

Figure 4

8. The final screen will ask you for the name the connection (enter “Win2K8R2Core”):

Page 10: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 5

Your server will now be listed on the Connections pane and the Management Console can now be used to configure web sites and ASP.NET applications as with a standard IIS Server installation.

Note: The screen-capture graphics herein may differ slightly from your physical lab experience.

Figure 6

Part 1: Add the New Web Site

1. Right-click the “Win2K8R2Core” node within the IIS Management Console tree-view and select “Add Web Site…”. Complete the dialog window as illustrated:

Page 11: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 7

Part 2: Add the New Web Application

1. Expand the “Sites” node to display the new “test” web site. Right-click the “test” node and select “Add Application”. Complete the dialog windows as illustrated:

Figure 8

Part 3: Enable Anonymous User Authentication

1. Select the ".NET Authorization Rules" configuration wizard and open the "test" web site to all anonymous users as illustrated in the following two graphics:

Page 12: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 9

Figure 10

Part 4: Browse to the New Web Application

1. From the Win2K8R2Dev machine, open a browser window and navigate to the web application (http://10.0.0.3:81/website) as illustrated:

Page 13: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 11

Exercise 3: Debug ASP.Net Applications on Server Core

Part 1: Deploying the remote debugger service

1. The first thing you must do is deploy the remote debugger service onto your Server Core host machine. From the Win2K8R2Core machine, repeat the following commands as illustrated:

mkdir c:\msvsmonxcopy \\10.0.0.1\SCRATCH\RemoteDebugger\*.* c:\msvsmon\*.* /Sc:\msvsmon\x64\msvsmon.exe

2. The x64 Visual Studio remote debugger service (msvsmon.exe) should now be listening for connections as illustrated (NOTE: You may also see a dialog asking which scope to enable firewall ports for the remote debugging monitor. Choose to open all ports at the subnet or global scope.):

Page 14: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 12

Part 2: Setting-up the Visual Studio Machine

1. On the Win2K8R2Dev machine, create an empty Visual Studio solution to host your application. Then select the option to Add an Existing Web Site to the solution as illustrated:

Page 15: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

Figure 13

2. When prompted to select the web site, don’t be tempted to select the Local IIS option, as we do not intend to debug the application with the local IIS service. Instead, select the File System option, and choose the folder that holds the ASP.NET application you wish to debug. In the screenshot below, the folder pointed by the red arrow is the folder that holds our sample ASP.NET application

Note: The project will be at c:\SCRATCH\website on the Win2K8R2Dev machine.:

Figure 14

Page 16: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

3. Once the project has been configured, it is just a matter of changing some of the default options from the project to make sure it connects to the remote Server Core install. The first task is to make sure that the Start Action is set to wait for an external application. This is done because, as you will see very soon, we will not be starting the application, but rather attaching to the remote process that is hosting the application:

Figure 15

Another option that must be configured is to select a custom server instead of the default Web Server. This is specified in the section below, and you must also specify the URL of the website you wish to debug on the remote server core install:

Note: Use http://10.0.0.3/website instead of the path illustrated in the graphic below.

Figure 16

4. Once you are ready to debug your application, place the corresponding breakpoint within the project file default.cs.

5. Load the web site by accessing the URL from the Win2K8R2Dev machine using Internet Explorer.

Note: Nothing should happen at this point, you are merely loading the web site so that the web server process on the host machine will run.

Page 17: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

6. Switch over to Visual Studio and from the Debug menu, select the Attach to Process… option. From the dialog, select the type of code to debug or else you will run into problems trying to debug your code later on. From the Attach to: portion of the dialog, click the Select button and only select the debug managed code check-box as shown below:

Figure 17

Note: Failure to carry-out this step will cause the debugger to try to debug T-SQL later-on when you do not intend on doing so.

7. You must now select the machine name from the Qualifier option. For instance, if your Server Core username is student1 and the name of your machine is Win2K8R2Core, you would select the following option:

Figure 18

The next step involves attaching to the w3wp.exe process from the list of available processes (you must select the option to show processes from all users in order to see this process). If the process still does not display, reload your web page using Internet Explorer and then switch back to the dialog and use the Refresh button. Once the process becomes available, select it and click the Attach button.

It is now a matter of carrying out the necessary steps in your ASP.NET application to hit any of

Page 18: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

the breakpoints you set. Once this happens, the breakpoint will be highlighted and you will be remotely debugging your ASP.NET code from within Visual Studio:

Figure 19

Hardware Requirements

This lab requires using Hyper-V Virtual Machines on a host workstation. The requirement for host machine is the following:

Hyper-V Capable Machine (either AMD or Intel)

At least 2 cores

At least 2 GB of RAM

At least 50 GB of free space

Ethernet Connection

Internet Connection (not critical)

Appendix A: Host Machine Configuration

Hardware Requirements

This lab requires using Hyper-V Virtual Machines on a host workstation. The requirements for the host workstation machine include the following:

Hyper-V Capable Machine (either AMD or Intel)

Page 19: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

At least 2 cores

At least 2 GB of RAM

At least 50 GB of free space

Ethernet Connection

Internet Connection (not critical)

Virtualization Host Configuration

1. Install Windows Server 2008 x64 R2 on the host computer (trial version will do).

a. http://www.microsoft.com/windowsserver2008/en/us/try-it.aspx

2. Enable the Hyper-V role.

3. Once Hyper-V is installed and enabled, create a “Private” virtual network and call it Private.

4. Create an “External” virtual network and call it Public.

5. Download the VHD images of Windows Server 2008 R2 and use these as starter .VHD files for your Hyper-V Virtual Machines.

a. http://www.microsoft.com/windowsserver2008/en/us/try-it.aspx

Appendix B: R2 Developer VM Configuration

Software Requirements

Operating System

Microsoft Windows Server 2008 R2 (Released Evaluation).

o http://www.microsoft.com/windowsserver2008/en/us/R2-Download.aspx

Developer Tools (install these as “full installations”)

Microsoft Visual Studio 2008 (an edition that includes x64 compilers)

◦ http://msdn.microsoft.com/en-us/downloads/default.aspx

Microsoft Visual Studio 2008 SP1 Upgrade

Page 20: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

◦ http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&displaylang=en

Windows® Software Development Kit (SDK) for Windows 7 and .NET Framework 3.5 Service Pack 1:

◦ ISO: http://www.microsoft.com/downloads/details.aspx?FamilyID=71deb800-c591-4f97-a900-bea146e4fae1&displaylang=en

◦ Web setup: http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en

Ensure that Visual Studio is installed to include the “x64 Compiler and Tools” as well as the “Visual Web Developer” option.

Ensure that the IIS Web Management administration console is installed.

Network Configuration

Open a command window with admin privileges and type the following command:

netsh interface ipv4 set address name="Local Area Connection" static 10.0.0.2 255.255.255.0 10.0.0.1

Note: Please note that running the command above will set the IP address of your machine to static one which disable Internet access. If you need Internet access, may we suggest adding an additional network adapter hooked up to your public network.

Appendix C : R2 Server Core VM Configuration

Virtual Machine Configuration

1. Name the machine in Hyper-V: Server 2008 R2 Core

2. Store the machine anywhere on the host

3. Allocate at least 512 MB of RAM

4. Make sure the VM is connected to the Private network

General Setup

1. Start the Windows Server 2008 R2 Installer by booting from the ISO

2. Install the Enterprise version of Windows Server 2008 Server Core

Page 21: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

3. When the machine reboots set the Administrator password to p@ssw0rd

4. Once the command prompt for administrator is shown, carry out the following steps:

5. Rename the computer:

netdom renamecomputer %COMPUTERNAME% /NewName:Server2008R2

6. You will need to reboot afterwards:

shutdown -f -r -t 0

7. When the machine reboots, log in and at the command prompt verify that the name change did take place by typing:

echo %COMPUTERNAME%

8. Change the IP address of the server by typing the following command:

netsh interface ipv4 set address name="Local Area Connection" static 10.0.0.1 255.255.255.0 10.0.0.1

9. Enable RDP support as follows:

cscript \windows\system32\scregedit.wsf /ar 0

10. Add the student1 user:

Net user student1 p@ssw0rd /add net localgroup “Administrators” student1 /add logoff <optional>

11. To set a static IP address

netsh interface ipv4 show interfaces <make a note of the ‘idx’ column number. Use it in the ID field below.> netsh interface ipv4 set address name="<ID>" source=static address=<StaticIP> mask=<SubnetMask> gateway=<DefaultGateway>

12. Allow Remote Administration

netsh advfirewall firewall set rule group="Remote Administration" new enable=yes

13. Share a drive:

Page 22: Build ASP.NET Applications for Windows Server Coreaz12722.vo.msecnd.net/windowsserver2008r2trainingcourse1... · Web viewWindows Server 2008 R2 Server Core includes a subset of the

Windows Server 2008 R2 Developer Readiness Server Core .NET Applications

net share “Drive_C”=c:\ /Grant:student1,Full