开发者

IP Address Parameter in ASP.Net

开发者 https://www.devze.com 2023-03-17 18:37 出处:网络
I have a stored procedure that inserts a few columns into a database, IP Address, Name, Comments. I am not sure how to get the ip address of the users machine. Perhaps I am to create a variable of the

I have a stored procedure that inserts a few columns into a database, IP Address, Name, Comments. I am not sure how to get the ip address of the users machine. Perhaps I am to create a variable of the same type (INT) and then store the IP Address in there. I am kinda of lost on this one.

static int IPAddress()
{ 
get { return Request.UserHostAddress; }; 
}//How do I pass from here into my stored procedure?


                cmdI.Parameters.Add(new SqlParameter("@IPAddress", cmdI));
                cmdI.Parameters.Add(new SqlParameter("@Name", cmdI));
                cmdI.开发者_运维百科Parameters.Add(new SqlParameter("@Comments", cmdI));


You need to convert the IP Address from a string to an int; see How to convert an IPv4 address into a integer in C#?

However, I would change the DB to store IP address as a string. This way you will support IPv6.


IP address is indeed a representation of a 32bit int and can be stored in the db as such

0

精彩评论

暂无评论...
验证码 换一张
取 消