要将一个ASMX方法始终设为HttpGet行为,可以在方法上添加[WebMethod]特性,并且设置其EnableSession属性为false。
以下是一个示例代码:
using System;
using System.Web.Services;
[WebService(Namespace = "http://example.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : WebService
{
[WebMethod(EnableSession = false)]
public string MyMethod(string parameter)
{
// 在这里编写方法的实现代码
return "Success";
}
}
在上面的示例中,MyMethod方法被标记为[WebMethod],并且EnableSession属性被设置为false。这意味着该方法始终作为HttpGet行为,而且不会使用会话状态。