Integrating Microsoft Terminal Services with SPS provides a good mechanism for accessing legacy applications directly from the portal. Such a solution could mean a significant reduction in client-side installations and maintenance for older applications. In this exercise, you will set up Terminal Services and create a web part to access an application.
Before you can set up Terminal Services, you need to provide a separate server. Do not attempt to install Terminal Services on SPSPortal or SPSController because the installation can interfere with other projects in the book. I have solved this problem by creating a VMWare session named TS2K3 . If you are not using a server consolidation product like VMWare, however, you will need a server capable of running Windows 2003.
Terminal Services should always be installed on the server as the first order of business after the operating system is installed. This is because applications that you want to access from Terminal Services must be installed after the server is configured or they will not be available. The rest of the exercise assumes that you have properly installed and configured Windows Server 2003, Enterprise Edition and joined it to the sps.local domain.
Select Start Manage Your Server to open the Manage Your Server page.
On the Manage Your Server page, click "Add or remove a role" to run the Configure Your Server wizard.
In the Configure Your Server wizard, click Next.
In the Server Role list, select Terminal Server.
Click Next.
View the summary screen and click Next.
After the installation is complete and the server reboots, click Finish.
In order to access Terminal Services through the portal, you will use the web-based client control that ships with Windows 2003. Web-based access to Terminal Services is not configured by default. It must be installed separately along with Internet Information Server (IIS).
Select Start Control Panel Add or Remove Programs.
In the Add or Remove Programs dialog, click Add/Remove Windows Components .
In the Windows Components wizard, click Application Server and then the Details button.
In the Application Server dialog, click Internet Information Services and then the Details button.
In the Internet Information Services dialog, click World Wide Web Service and then the Details button.
In the World Wide Web Service dialog, check Remote Desktop Web Connection.
Click OK.
In the Internet Information Service dialog, click OK.
In the Application Server dialog, check ASP.NET and then click OK.
In the Windows Components wizard, click Next.
When installation is complete, click Finish.
Once you have installed the web-based Terminal Services client, you can test it from any browser. The web client installation comes with a default web page that can be used immediately to access a terminal server. The actual functionality is provided by an ActiveX control that is automatically downloaded when the page is accessed.
Log in to SPSClient .
Open an instance of Internet Explorer.
Navigate the browser to http://ts2k3/tsweb/default.htm to view the Remote Desktop Web Connection page.
In the Remote Desktop Web Connection page, type TS2K3 into the Server box.
In the Size drop-down box select 800 by 600.
Click Connect.
Use your administrator credentials to log in to TS2K3 .
Log off of TS2K3 .
Close Internet Explorer.
Once you have verified that the web client is working correctly, you will need to configure Terminal Services for this exercise. By default, Terminal Services always logs remote users into a desktop session. Additionally, the default configuration always requires the user to enter a user name and password. In this example, you will configure Terminal Services to provide access to a single application through a common set of credentials. This will allow you to provide access to the application through the portal.
Select Start Administrative Tools Terminal Services Configuration.
In the configuration dialog, open the Connections folder.
Right-click the RDP-Tcp connection and select Properties from the popup menu.
On the Environment tab, check the "Override settings from user profile and Remote Desktop Connection or Terminal Services client" box.
In the "Program path and file name" text box, type c:\windows\notepad.exe to make Notepad the application that runs when a user connects to Terminal Services.
On the Logon Settings tab, select the "Always use the following logon information" option.
Enter a user name and password with permission to log on to the server and run the application.
Click OK.
Note | Configuring Terminal Services to run a single application is best done by creating a policy in Active Directory. You are configuring the server directly to simplify the exercise. Consult the help documentation for Terminal Services for best practices. |
Although you can use the default web page that installs with the remote desktop connection components, typically you will want to modify the page. In this exercise, you will create your own simple ASP.NET page that accepts query string parameters as input. When the parameters are received, you will use ASP.NET to write a client-side script that will use the Terminal Services ActiveX control.
Log on to SPSPortal as the domain administrator.
Start Visual Studio .NET.
Select File New Project from the menu.
In the Add New Project dialog, open the Visual Basic Projects folder.
Select to create a new ASP.NET web application.
In the Location text box, type http://ts2k3/SPSTSWeb .
Note | Ensure that the wwwroot directory is shared on TS2K3 or Visual Studio will not be able to create the project. |
Click OK.
In the Solution Explorer, rename WebForm1.aspx to Default.aspx .
In the Solution Explorer, open the code view for the page Default.aspx .
Modify the Page_Load event to generate the client-side HTML and script as shown in Listing 7-11.
Listing 7-11: Creating the HTML and Script
Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load With Response .Write(vbCrLf) .Write("<script language=""VBScript"">" + vbCrLf) .Write("<!" + vbCrLf) .Write("Sub StateChange" + vbCrLf) .Write(" set RDP = Document.getElementById(""MsRdpClient"")" + vbCrLf) .Write(" If RDP.ReadyState = 4 Then" + vbCrLf) .Write(" RDP.Server = """ + Request.QueryString("Server") + """" + vbCrLf) .Write(" RDP.FullScreen = " + Request.QueryString("FullScreen") + vbCrLf) .Write(" RDP.DesktopWidth = """ + Request.QueryString("DesktopWidth") _ + """" + vbCrLf) .Write(" RDP.DesktopHeight = """ + Request.QueryString("DesktopHeight") _ + """" + vbCrLf) .Write(" RDP.AdvancedSettings2.RedirectDrives = " _ + Request.QueryString("RedirectDrives") + vbCrLf) .Write(" RDP.AdvancedSettings2.RedirectPrinters = " _ + Request.QueryString("RedirectPrinters") + vbCrLf) .Write(" RDP.FullScreenTitle = """ + Request.QueryString("Title") + _ """" + vbCrLf) .Write(" RDP.Connect" + vbCrLf) .Write(" End If" + vbCrLf) .Write("End Sub" + vbCrLf) .Write(">" + vbCrLf) .Write("</script>" + vbCrLf) .Write(vbCrLf) .Write("<OBJECT ID=""MsRdpClient"" Language=""VBScript""" + vbCrLf) .Write("CLASSID=""CLSID:7584c670-2274-4efb-b00b-d6aaba6d3850""" + vbCrLf) .Write("CODEBASE=""msrdp.cab#version=5,2,3790,0""" + vbCrLf) .Write("OnReadyStateChange=""StateChange""" + vbCrLf) .Write("WIDTH=""" + Request.QueryString("DisplayWidth") + """" + vbCrLf) .Write("HEIGHT=""" + Request.QueryString("DisplayHeight") + """" + vbCrLf) .Write("</OBJECT>" + vbCrLf) End With End Sub
Once the web page is correctly modified, select Build Build SPSTSWeb from the menu.
The ASP.NET web application created in the previous steps could be called directly from any browser to access Terminal Services using the web client. However, you will want to integrate the functionality into SPS by creating a web part that will dynamically build a hyperlink to call the page. The hyperlink will be created based on several properties of the web part. In this way, you will be able to configure access to Terminal Services using the properties of the web part.
Because you should be reasonably adept at creating the basic framework for a web part, I will not repeat the detailed instructions here. Simply open Visual Studio and create a new web part project using VB.NET. Name the new project SPSTerminal and name the class Client .
Your web part is limited to creating a simple hyperlink based on the properties necessary to access the Terminal Services web client. Although there are several properties, each of them corresponds to a value required by the Terminal Services web client. Add code to your web part to define the properties in Table 7-5.
NAME | TYPE | DEFAULT VALUE | DESCRIPTION |
---|---|---|---|
URL | String | ” | The URL where the web client ASP.NET page is located |
Server | String | ” | The name of the Terminal Services server |
FullScreen | Boolean | False | Determines if the Terminal Services session runs in full screen mode |
DisplayWidth | String | 100% | Specifies the relative width of the session viewer |
DisplayHeight | String | 100% | Specifies the relative height of the session viewer |
DesktopWidth | Integer | 800 | Specifies the width of the Terminal Services desktop |
DesktopHeight | Integer | 600 | Specifies the height of the Terminal Services desktop |
RedirectDrives | Boolean | False | Determines if the client drives are mapped to the Terminal Services session |
RedirectPrinters | Boolean | True | Determines if the client printers are mapped to the Terminal Services session |
Because you are simply creating a hyperlink as the sole interface element of the web part, no child controls are required. All you have to do is create the hyperlink in the RenderWebPart method. Add the code in Listing 7-12 to create the hyperlink for the web part.
Protected Overrides Sub RenderWebPart(_ ByVal output As System.Web.UI.HtmlTextWriter) With output Dim strConnectURL As String = "" strConnectURL += URL strConnectURL += "?Server=" + Server strConnectURL += "&FullScreen=" + FullScreen.ToString strConnectURL += "&DeskTopWidth=" + DesktopWidth.ToString strConnectURL += "&DeskTopHeight=" + DesktopHeight.ToString strConnectURL += "&DisplayWidth=" + DisplayWidth strConnectURL += "&DisplayHeight=" + DisplayHeight strConnectURL += "&RedirectDrives=" + RedirectDrives.ToString strConnectURL += "&RedirectPrinters=" + RedirectPrinters.ToString strConnectURL += "&Title=" + Title .Write("<a href=""" + strConnectURL + """ Target=""_blank"">" & _ "Connect to " + Server + "</a><br>" + vbCrLf) End With End Sub
Deploying the Terminal Services web part is no different than deploying any basic web part. No special permissions are required for the part to run, so you should modify the web part description file appropriately, generate a strong name, build the part, and mark it as safe. You have already performed these steps several times in various exercises, so I will not repeat the steps here.
Once the web part is properly compiled, you should be able to add it to a site in SPS. The web part itself is an unassuming hyperlink; however, it should access the Terminal Services client when properly configured. Set the properties for the web part as listed in Table 7-6. Then click the hyperlink and verify that Notepad starts in a Terminal Services session.
NAME | VALUE |
---|---|
URL | http://ts2k3/SPSTSWeb/Default.aspx |
Server | ts2k3 |
FullScreen | False |
DisplayWidth | 100% |
DisplayHeight | 100% |
DesktopWidth | 800 |
DesktopHeight | 600 |
RedirectDrives | False |
RedirectPrinters | True |
Note | The Remote Desktop ActiveX control must be installed on the client accessing Terminal Services. |