المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : identify authorised user on web method using c#



C# Programming
02-23-2010, 08:11 PM
Hi everyone,

Does anyone have any idea how to do the following code snippet i posted below in web method?



protected void Page_Load(object sender, EventArgs e)
{
// Get the hostname
string myHost = System.Net.Dns.GetHostName();
// Get the IP from the host name
//string myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[0].ToString();

string connect = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\\inetpub\\wwwroot\\Request\\App_Data\\TV.mdb";
string query = "SELECT COUNT(IPAddress) FROM Request WHERE IPAddress = ?";
int result = 0;

using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("IPAddress", myHost);

conn.Open();
result = (int)cmd.ExecuteScalar();
}
}
if (result