A Web behavior lets you define a custom response that is returned when a rule is triggered for a tracked web resource. For example, if a Web API triggers a flow control rule, you can return a message such as "Blocked by Sentinel". This topic describes how to add, modify, delete, and associate a Web behavior.
Prerequisites
Your application is connected to AHAS Application Protection. For more information, see Application connection methods.
Background information
Configuring a behavior is primarily about setting up a fallback behavior. Fallback behaviors are available for Web and RPC resource types. This topic describes how to configure a fallback behavior for Web resources.
Add behavior
Log on to the AHAS console and select a region in the upper-left corner.
- In the left-side navigation pane, choose .
- On the Application Protection page, click the card of your target application.
In the left-side navigation pane, choose Application Management and then click the Behavior Management tab.
Click Add Behavior. In the Add Behavior dialog box, configure the following parameters and then click Create.
Parameter
Description
Example
Behavior Name
A unique name for the behavior within the application, up to 128 characters.
test-behavior
Resource Type
The resource type. Select Web.
Web
Web Throttling Policy
The action to take when a rule is triggered for a Web API. Options include:
Custom Response: Returns a custom response. You must specify the HTTP status code, content type, and body.
Redirect to a specified page: Redirects the request to a specified URL.
Custom Response
HTTP Status Code
Required if Web Throttling Policy is set to Custom Response. Default: 429.
429
Content-Type
The format of the response body. Valid values: TEXT and JSON. This parameter is required when Web Throttling Policy is set to Custom Response.
JSON
HTTP Body
The content of the response body. This parameter is required when Web Throttling Policy is set to Custom Response.
{"message": "blocked oops"}
Redirect URL
The URL to which the system redirects requests when the Web API triggers the rule. This parameter is required when Web Throttling Policy is set to Redirect to a specified page.
NoteThe redirect action returns an HTTP 302 status code. This redirect is effective for backend-rendered pages but not for frontend-rendered pages that rely on AJAX requests.
http://ahas.console.aliyun.com
The new behavior appears on the Behavior Management tab of the Application Management page.
Modify or delete behavior
Log on to the AHAS console and select a region in the upper-left corner.
- In the left-side navigation pane, choose .
- On the Application Protection page, click the card of your target application.
In the left-side navigation pane, choose Application Management and then click the Behavior Management tab.
On the behavior list page, you can view, modify, or delete behaviors.
Associate behavior
Log on to the AHAS console and select a region in the upper-left corner.
- In the left-side navigation pane, choose .
- On the Application Protection page, click the card of your target application.
Use one of the following methods to open the Add Flow Control Rule page:
In the left-side navigation pane, click API Details. On the Web Service tab, click the
icon in the upper-right corner of the target API card to go to the Manage Rules page. Then, click Add Flow Control Rule.In the left-side navigation pane, click Rule Management. On the Flow Control Rules tab, click Add Flow Control Rule.
In the Configure Flow Control Behavior section, configure the following settings.
Set API Type to Web.
From the Associate Behavior drop-down list, select the target behavior. Alternatively, click Add Behavior to create and associate a new behavior.
NoteIf you do not need a custom fallback behavior for flow control, you can use the default behavior. For the default behavior, the API type is not specified.
When you add a rule, if the API already has an associated behavior, the new behavior overwrites the existing one.
If you do not select an API type, the system uses the default behavior. Once you associate a behavior for a specific API type, you cannot change the API type for that rule.
Click Next and then click Add.