why I cannot get the REMOTE_ADDR?

NETANEL.S

Member
Joined
Feb 14, 2019
Messages
21
Programming Experience
3-5
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WindowsService1.mvc1.Controllers
{
    public class HomeController : Controller
    {....
        public string sedtip()
        {
            

            return Request.ServerVariables["REMOTE_ADDR"];
        }
    }
}
this code throws exception.
why it's happend???
 
What exception? Please ALWAYS provide a FULL and CLEAR explanation of the problem. Tell us what you're trying to achieve, how you're trying to achieve it and what happens when you try.
 
A NullReferenceException occurs when you try to access a member of an object that doesn't exist. If the exception occurs on the line of code you posted it means that you haven't assigned anything to the Request variable.
 
A NullReferenceException occurs when you try to access a member of an object that doesn't exist. If the exception occurs on the line of code you posted it means that you haven't assigned anything to the Request variable.
What I can to do for get the client's public IP address?
 
What I can to do for get the client's public IP address?
If you have a new question then please create a new thread with the information relevant to that question. As far as this topic is concerned, I've told you that the issue is that you have not assigned anything to the Request variable. The obvious solution is the assign something to the Request variable.
 
Back
Top Bottom