Created
October 12, 2023 05:44
-
-
Save sreekrishnan1993/3d5f6f9829313a693dbf0b1ca817e80b to your computer and use it in GitHub Desktop.
Get Device Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetDeviceInfo.aspx.cs" Inherits="MyProject.Foundation.SitecoreSupport.sitecore.admin.GetDeviceInfo" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<asp:Button ID="btnClick" runat="server" Text="Click Me!!!" OnClick="btnClick_Click"></asp:Button> | |
<asp:Label ID="Label1" runat="server"></asp:Label> | |
</div> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Caching; | |
using Sitecore.CES.DeviceDetection; | |
using Sitecore.CES.DeviceDetection.Cache; | |
using Sitecore.CES.DeviceDetection.Providers.FiftyOneDegrees; | |
using Sitecore.Threading.Locks; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace MyProject.Foundation.SitecoreSupport.sitecore.admin | |
{ | |
public partial class GetDeviceInfo : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
protected void btnClick_Click(object sender, EventArgs e) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
string userAgent = string.Empty; | |
if (Request.Headers.AllKeys.Contains("User-Agent")) | |
{ | |
userAgent = Request.Headers["User-Agent"].ToString(); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("User Agent = " + userAgent); | |
sb.AppendLine("<br>"); | |
} | |
DeviceDetectionCache DeviceCache = new DeviceDetectionCache(); | |
DeviceInformation deviceInformation = DeviceCache.GetDeviceInformation(userAgent); | |
sb.AppendLine("Device Type = " + deviceInformation.DeviceType.ToString()); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("DeviceModelName = " + deviceInformation.DeviceModelName); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("DeviceIsSmartphone = " + deviceInformation.DeviceIsSmartphone); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("IsBot = " + deviceInformation.IsBot); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("CanTouchScreen = " + deviceInformation.CanTouchScreen); | |
sb.AppendLine("<br>"); | |
sb.AppendLine("Operating System = " + deviceInformation.DeviceOperatingSystemModel); | |
sb.AppendLine("<br>"); | |
Label1.Text = sb.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment