位置:首页 > 编程专栏 > C#

ASP.NET ashx获取客户端ip, 请求ip

ASP.NET ashx获取客户端ip, 请求ip
using System.Web;

namespace WebApplication6
{
    /// <summary>
    /// Summary description for Demo2
    /// </summary>
    public class Demo2 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("IP: " + context.Request.UserHostAddress.ToString());
            context.Response.Write("IP: " + HttpContext.Current.Request.UserHostAddress.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


C# 社区推荐