请求用户代理每次输出Mozilla / 5.0

时间:2014-09-30 17:43:46

标签: c#

您好我正在运行SuccessLogin()函数,并在导入userAgent或浏览器名称时检测我是否在ipad,iphone或桌面Chrome上,或者我使用此代码的任何内容。

public void SucessLogin()
{
    String userAgent;
    userAgent = Request.UserAgent;

    using (SqlConnection sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString))
    {
        using (SqlCommand sqlCmd1 = new SqlCommand { CommandText = "INSERT INTO dbo.loginaudit ([login], [timestamp], [device], [loginerror]) VALUES (@login, @time, @device, 'Success')", Connection = sqlCon })
        {
            sqlCmd1.Parameters.AddWithValue("@time", DateTime.Now);
            sqlCmd1.Parameters.AddWithValue("@device", userAgent);
            sqlCmd1.Parameters.AddWithValue("@login", txtLoginID.Text);
            sqlCmd1.Parameters.AddWithValue("@pass", txtPassword.Text);
            sqlCon.Open();
            {

                sqlCmd1.ExecuteNonQuery();

                sqlCon.Close();
            }
        }
    }
}

然而,当我在IE或Chrome上时,它会在数据库中输出。

铬:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36

Internet Explorer:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

有没有办法解决这个问题?

0 个答案:

没有答案