Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

ScriptMethodAttribute Class

Specifies which HTTP verb is used to invoke a method and the format of the response. This class cannot be inherited.

Syntax

CSharp

[AttributeUsageAttribute(AttributeTargets.Method)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ScriptMethodAttribute : Attribute

VisualBasic

<AttributeUsageAttribute(AttributeTargets.Method)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class ScriptMethodAttribute _
	Inherits Attribute

ManagedCPlusPlus

[AttributeUsageAttribute(AttributeTargets::Method)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ScriptMethodAttribute sealed : public Attribute

JSharp

/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public final class ScriptMethodAttribute extends Attribute

Members

IconMemberDescription
ScriptMethodAttributeNew()Initializes a new instance of the ScriptMethodAttribute class.
Equals(Object)Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Finalize()Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode()Returns the hash code for this instance. (Inherited from Attribute.)
GetType()Gets the Type of the current instance. (Inherited from Object.)
IsDefaultAttribute()When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Match(Object)When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
MemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
ResponseFormatGets or sets the format of the method response.
ToString()Returns a String that represents the current Object. (Inherited from Object.)
TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
UseHttpGetGets or sets a value indicating whether to invoke the method by using HTTP GET.
XmlSerializeStringGets or sets a value indicating whether all return types are serialized as XML, including string types.

Remarks

The use of the ScriptMethodAttribute attribute is optional, but the method must have the WebMethodAttribute attribute applied to be invoked from ECMAScript (JavaScript). If ScriptMethodAttribute is not included, the method will be called by using the HTTP POST command and the response will be serialized as JavaScript Object Notation (JSON). You cannot override this setting from script. The use of ScriptMethodAttribute should be considered carefully.

ScriptMethodAttribute only takes named parameters. The following are the properties of ScriptMethodAttribute that can be used as named parameters:

  • UseHttpGet

    Specifies whether the method will be invoked by using the HTTP GET command. The default is false. Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions.

  • ResponseFormat

    Specifies whether the response will be serialized as JSON or as XML. The default is Json. The ResponseFormat property is useful for scenarios where the return type of the method is XmlDocument or XmlElement.

  • XmlSerializeString

    Specifies whether all return types, including string types, are serialized as XML. The value of the XmlSerializeString property is ignored when the response is serialized as JSON.

For more information about using attributes, see Extending Metadata Using Attributes.

Examples

The following example demonstrates how to apply ScriptMethodAttribute to the GetXmlDocument and EchoStringAndDate methods to specify which HTTP verb to use and the response format.

Permissions

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: LinkDemand. Associated enumeration: Minimal.

Inheritance Hierarchy

Object

Assembly: System.Web.Extensions (Module: System.Web.Extensions)