IPAddress of a login system

前端 未结 6 2514
花落未央
花落未央 2020-12-22 05:42

Using the bellow code .

protected string GetUserIP()
{
    string strUserIP = string.Empty;
    if (HttpContext.Current.Request.ServerVariables[\"HTTP_X_FORW         


        
6条回答
  •  情话喂你
    2020-12-22 06:15

    Method that gets IP address: ASP.NET, C#

    using System;
    using System.Web;
    
    namespace WebApplication1
    {
        public class Global : HttpApplication
        {
          protected void Application_BeginRequest(object sender, EventArgs e)
          {
            // Get request.
            HttpRequest request = base.Request;
    
            // Get UserHostAddress property.
            string address = request.UserHostAddress;
    
            // Write to response.
            base.Response.Write(address);
    
            // Done.
            base.CompleteRequest();
          }
        }
    }
    

提交回复
热议问题