Share via


AntiForgery.GetHtml Method

Adds an authenticating token to a form to help protect against request forgery.

Namespace:  System.Web.Helpers
Assembly:  System.Web.WebPages (in System.Web.WebPages.dll)

Syntax

'Declaration
Public Shared Function GetHtml As HtmlString
'Usage
Dim returnValue As HtmlString 

returnValue = AntiForgery.GetHtml()
public static HtmlString GetHtml()
public:
static HtmlString^ GetHtml()
static member GetHtml : unit -> HtmlString
public static function GetHtml() : HtmlString

Return Value

Type: System.Web.HtmlString
Returns a string that contains the encrypted token value in a hidden HTML field.

Exceptions

Exception Condition
ArgumentException

The current System.Web.HttpContext object is null reference (Nothing in Visual Basic).

Remarks

Call this method to create an encrypted token that is added to an HTML form as a hidden field. After the page has been submitted, you can call the Validate() method to check the token value and validate that the submitted data comes from a valid user.

Use the GetHtml method overload when you do not have to specify any additional parameters for the method. If you want to specify parameters (such as a salt value for enhanced encryption, a virtual application path, or a domain within which to validate the request), use the GetHtml overload.

See Also

Reference

AntiForgery Class

GetHtml Overload

System.Web.Helpers Namespace