Retrieving User Information

Discussion in 'ASP .Net' started by Dave, Aug 4, 2010.

  1. Dave

    Dave Guest

    I'm trying to adjust my default.aspx page to see if the user is
    accessing it from a smart phone. In a previous post someone suggested
    using Page.Request.UserAgent. After reviewing the possibilities I
    added the below code to my Page_Load.

    The below runs fine in Visual Studio. When moving it out to my Web
    Server sitting in the DMZ none of the varialbes are returning. No
    errors are being generated and the Stored Procedure doesn't even show
    up in Profiler. I've tried dropping everything and just putting a
    Response.Write("Test")....It's as if the Page_Load isn't even firing.
    It should be noted that this is the home page in the web. Any
    thoughts or suggested?

    Thanks

    *****CODE****

    namespace Web
    {
    public partial class _default : System.Web.UI.Page
    {
    ReportError rE = new ReportError();
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    rE.Error = "";

    string a = Page.Request.UserAgent.ToString();
    string b = Page.Request.UserHostAddress.ToString();
    string c = Environment.MachineName.ToString();

    string strConnection =
    ConfigurationManager.ConnectionStrings["VortexConnectionString"].ConnectionString;
    using (SqlConnection connection = new
    SqlConnection(strConnection))
    {
    SqlCommand command = new SqlCommand();
    command.Connection = connection;
    command.CommandText = "UserAgentInfo_INSERT";

    command.Parameters.AddWithValue("@UserAgent",
    a.ToString());

    command.Parameters.AddWithValue("@UserHostAddress", b.ToString());
    command.Parameters.AddWithValue("@UserHostName",
    c.ToString());

    command.Parameters.Add("@ErrorCode",
    SqlDbType.VarChar, 50);
    command.Parameters["@ErrorCode"].Direction =
    ParameterDirection.Output;
    command.Parameters.Add("@ErrorMessage",
    SqlDbType.VarChar, 500);
    command.Parameters["@ErrorMessage"].Direction =
    ParameterDirection.Output;

    command.CommandType = CommandType.StoredProcedure;

    connection.Open();
    command.ExecuteNonQuery();

    connection.Close();
    }

    }
    catch (Exception ex)
    {
    rE.Error = ex.Message;
    }
    }
    }
    }
    Dave, Aug 4, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob
    Replies:
    2
    Views:
    4,347
  2. Boban Dragojlovic
    Replies:
    2
    Views:
    458
    Patrice
    Apr 19, 2004
  3. =?Utf-8?B?SWFuIFdpbGxpYW1zb24=?=

    Retrieving state information from a middle tier

    =?Utf-8?B?SWFuIFdpbGxpYW1zb24=?=, Feb 25, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    1,258
    =?Utf-8?B?aW5ldG11Zw==?=
    Feb 25, 2005
  4. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    Retrieving mailbox information through ADSI

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Aug 31, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    =?Utf-8?B?ZG90bmV0dGVzdGVy?=
    Aug 31, 2005
  5. Geoffry Smith
    Replies:
    2
    Views:
    151
Loading...

Share This Page