asp.net创建webapi

来源:互联网 发布:手机看书软件免费下载 编辑:程序博客网 时间:2024/05/16 12:35

1、添加一般应用程序,默认名Handler1.ashx,名字自己更改

2、通过HttpContext.Current.Request.QueryString["参数名"]获取参数

string id = HttpContext.Current.Request.QueryString["id"];
3、整体如下

using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace Api_WebForm{    /// <summary>    /// Handler1 的摘要说明    /// </summary>    public class Handler1 : IHttpHandler    {        public void ProcessRequest(HttpContext context)        {            string id = HttpContext.Current.Request.QueryString["id"];            context.Response.ContentType = "text/plain";            context.Response.Write("Hello World");        }        public bool IsReusable        {            get            {                return false;            }        }    }}


0 0
原创粉丝点击