다음을 통해 공유


ASP Page Examples

You can use an ASP page on a Web server to create a customized playlist that can be downloaded to a Windows Media server. You can place a reference to the ASP page in a playlist or in the IWMSPublishingPoint.PathIWMSPublishingPoint.Path (Visual Basic .NET) property. For example, if the client connects to a publishing point and requests a playlist, you can embed information about the client in the query component of the URL requested by the playlist. The ASP page can retrieve information from the query string, and use it to create a playlist tailored to the client. If the client requests the following playlist, the Windows Media server sends the IP address and user name to the Web server.

    <?wsx version="1.0"?>
    <smil>
        <media src="httpd://web_server/playlist.asp?
                            user=%UserName%&amp;
                            userIP=%UserIP%" />
    </smil>

The ASP page can use this information to determine what content to send to the client, as shown in the following example code. If you are using Internet Information Server (IIS) as your Web server, place the ASP page in the home directory. This is generally \Inetpub\wwwroot.

<% OPTION EXPLICIT %>
<smil>

  <media src="c:\wmpub\wmroot\ad1.wmv" />
<%
    ' Declare variables.
     Dim strUser, strUserId, strUserIP

    ' Retrieve the variables from the query string.
    strUser= Request.QueryString("user")
    strUserIP= Request.QueryString("userIP")

    ' Modify the playlist depending on the identity of the user.
    If strUserIP = "xxx.xxx.xxx.xxx" Then
        Response.Write("  <media src=""c:\wmpub\wmroot\ad2.wmv"" />")
        Response.Write(vbCrLf)
    End If
    ElseIf strUser = "user_name" Then
        Response.Write("  <media src=""c:\wmpub\wmroot\ad3.wmv"" />")
    Else
        Response.Write("  <media src=""c:\wmpub\wmroot\ad4.wmv"" />")
    End If

%>
  <media src="c:\wmpub\wmroot\movie1.wmv" />

</smil>

The following ASP page applies a subnet mask to the IP address sent in the query string. This enables you to send content to a range of addresses.

<% OPTION EXPLICIT %>
<smil>

  <media src="c:\wmpub\wmroot\ad1.wmv" />
<%

    ' Declare variables.
    Dim strIPAddrIn, strIPAddrMasked, strQuad
    Dim lngQuad(4), lngMask(4)
    Dim lngPos, lngOldPos, lngLength, lngStart
    Dim strSearchFor, I

    ' Set the mask to 255.255.252.000.
    lngMask(0) = CLng(255)
    lngMask(1) = CLng(255)
    lngMask(2) = CLng(252)
    lngMask(3) = CLng(0)

    ' Initialize the masked address and specify "." as the 
    ' search string.
    strIPAddrMasked = ""
    strSearchFor = "."

    ' Retrieve the client IP address from the query string.
    strIPAddrIn= Request.QueryString("userIP")

    ' Create a masked IP address.
    lngStart = 1
    lngOldPos = 0
    For I = 0 To 3
        
        ' Find either the position of each consecutive "."
        ' or the length of the IP address string.
        lngPos = InStr(lngStart, strIPAddrIn, strSearchFor)
        If I = 3 Then
            lngPos = Len(strIPAddrIn) + 1
        End If
    
        ' Determine the length of the quad being searched for.
        lngLength = lngPos - lngOldPos - 1
    
        ' Find the quad and mask it.
        strQuad = Mid(strIPAddrIn, lngStart, lngLength)
        lngQuad(I) = CLng(strQuad) And lngMask(I)
    
        ' Build the masked IP address string.
        strIPAddrMasked = strIPAddrMasked & CStr(lngQuad(I))
        If I <> 3 Then
            strIPAddrMasked = strIPAddrMasked & "."
        End If
    
        ' Set the counters.
        lngStart = lngPos + 1
        lngOldPos = lngPos
    Next


    If strIPAddrMasked = "172.29.236.0" Then
        Response.Write("  <media src=""c:\wmpub\wmroot\welcome2.asf"" />")
    Else
        Response.Write("  <media src=""c:\wmpub\wmroot\welcome3.asf"" />")
    End If

%>
  <media src="c:\wmpub\wmroot\18MIN.wmv" />

</smil>

You can use the server object model to retrieve the playlist object created by an ASP page. For more information, see Retrieving a Requested Playlist Object.

See Also

Concepts

Downloading a Playlist from a Web Server