AddWebPublishingRule Method of the IFPCPolicyRules Interface

The AddWebPublishingRule method creates a new FPCPolicyRule object representing a Web publishing rule in the collection and returns a reference to it.

[C++]

Syntax

HRESULT AddWebPublishingRule(
  [in]   BSTR Name,
  [out]  IFPCPolicyRule** ppNewRule
);

Parameters

Name
Required. BSTR that specifies the name of the new Web publishing rule.
ppNewRule

Address of an interface pointer that on return points to an IFPCPolicyRule interface representing the new Web publishing rule.

Return Value

This method returns one of the following:

[Visual Basic]

Syntax

Function AddWebPublishingRule( _
  ByVal Name As String _
) As FPCPolicyRule

Parameters

Name
Required. String that specifies the name of the new Web publishing rule.

Return Value

This method returns a reference to the FPCPolicyRule object if the operation is successful. Otherwise, an error is raised that can be intercepted by using an error handler.

Example Code

This VBScript script creates a Web publishing rule with default properties and uses property values provided by the user to set the properties that must be set before the rule saved to persistent storage.
Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_WebListenerNotFound = &HC0040357
Main(WScript.Arguments)
Sub Main(args)
	If(4 <> args.Count) Then
		Usage()
	End If
	AddWebPubRule args(0), args(1), args(2), args(3)
End Sub
Sub AddWebPubRule(ruleName, serverName, publicName, wlName)
	' Create the root object.
	Dim root  ' The FPCLib.FPC root object
	Set root = CreateObject("FPC.Root")
	'Declare the other objects needed.
	Dim tmgArray	 ' An FPCArray object
	Dim rules		' An FPCPolicyRules collection
	Dim rule		 ' An FPCPolicyRule object
	Dim publicNames  ' An FPCPublicNames collection
	' Get references to the array object
	' and the policy rules collection.
	Set tmgArray = root.GetContainingArray()
	Set rules = tmgArray.ArrayPolicy.PolicyRules
	On Error Resume Next
	Set rule = rules.Item(ruleName)
	If err.Number = Error_FileNotFound Then
		WScript.Echo "Creating the new Web publishing rule ..."
		Err.Clear
		Set rule = rules.AddWebPublishingRule(ruleName)
	Else
		WScript.Echo "The " & ruleName & " Web publishing rule already exists."
		WScript.Quit
	End If
	On Error GoTo 0
	' Set rule properties.
	rule.WebPublishingProperties.WebSite = serverName
	Set publicNames = rule.WebPublishingProperties.PublicNames
	publicNames.Add(publicName)

	On Error Resume Next
	rule.WebPublishingProperties.SetWebListener(wlName)
	If err.Number = Error_WebListenerNotFound Then
		WScript.Echo "The Web listener " & wlName & " does not exist. Aborting ..."
		WScript.Quit
	End If
	On Error GoTo 0
	' Save change.
	rules.Save
	WScript.Echo "Done!"
End Sub 
Sub Usage()
	WScript.Echo "Usage:" & VbCrLf _
		& "  " & WScript.ScriptName & " RuleName ServerName PublicName WLName" & VbCrLf _
		& "" & VbCrLf _
		& "  RuleName - Name of the new Web publishing rule" & VbCrLf _
		& "  ServerName - Name of the published Web server" & VbCrLf _
		& "  PublicName - Public Name of the Web server" & VbCrLf _
		& "  WLName - Name of the Web listener to be used" 
	WScript.Quit
End Sub

Remarks

The name assigned to the new rule must be unique. If the AddWebPublishingRule method is called with the name of an existing policy rule, the method fails.

A Web publishing rule maps public DNS names and IP addresses to the name or IP address of a Web server located behind the Forefront TMG computer and maps external paths that can be used by users in incoming requests to internal paths of directories on the published Web server. A Web publishing rule also determines how Forefront TMG should handle incoming requests for HTTP objects on the internal Web server and how Forefront TMG should respond on behalf of the internal Web server. Requests are forwarded downstream to the internal Web server. If possible, the requests are serviced from the Forefront TMG cache.

Before the properties of a new Web publishing rule can be written to persistent storage by calling the Save method, the following tasks must be performed:

When an enterprise with central array management is deployed, a Web publishing rule cannot be created in an array policy if the enterprise administrator sets the EnablePublishingRules property of the FPCPolicyAssignment object (IFPCPolicyAssignment interface in C++) for the array to False (VARIANT_FALSE in C++).

Requirements

Client Requires Windows Vista or Windows XP.
Server Requires Windows Server 2008.
Version Requires Forefront Threat Management Gateway (TMG).
IDL

Declared in Msfpccom.idl.

DLL

Requires Msfpccom.dll.

See Also

FPCPolicyRules


Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.