Device Detection of WURFL for Mobiles
Posted: Fri Dec 12, 2014 4:27 am
Hi Team,
I am using .NET API of WURFL for Mobile detection. Device detection is not working fine some times. Mobile site shows desktop views. Issue is with body part that loads desktop view. Header & Footer shows Mobile.
I am using the WURFL version 1.5.1.0.
Global.asax.cs
protected override void Application_Start()
{
base.Application_Start();
BundleConfig.RegisterBundles(BundleTable.Bundles);
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
ModelBinders.Binders.Add(typeof(DateTime), new ShortLittleEndianDateBinder());
ModelBinders.Binders.Add(typeof(DateTime?), new ShortLittleEndianDateBinder());
LoadWurflData(Context);
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
{
ContextCondition = (context =>
{
var manager = (context.Cache[WurflManagerCacheKey] as IWURFLManager);
if (manager == null)
{
var server = Context.Server;
var appSettings = WebConfigurationManager.AppSettings;
var wurflDataFile = appSettings["WurflDataFilePath"];
var wurflPatchFile = appSettings["WurflPatchFilePath"];
var configurer = new InMemoryConfigurer()
.MainFile(wurflDataFile)
.PatchFile(wurflPatchFile);
manager = WURFLManagerBuilder.Build(configurer);
}
var cabablities = manager.GetDeviceForRequest(context.Request.UserAgent);
return cabablities.GetCapability("is_wireless_device") == "true";
//return cabablities.GetCapability("mobile_browser").Contains("Opera");
//return cabablities.UserAgent.Contains("Opera");
})
});
}
public static void LoadWurflData(HttpContext context)
{
var server = context.Server;
var appSettings = WebConfigurationManager.AppSettings;
var wurflDataFile = appSettings["WurflDataFilePath"];
var wurflPatchFile = appSettings["WurflPatchFilePath"];
var configurer = new InMemoryConfigurer()
.MainFile(wurflDataFile)
.PatchFile(wurflPatchFile);
var manager = WURFLManagerBuilder.Build(configurer);
context.Cache[WurflManagerCacheKey] = manager;
}
Layout.Mobile.cshtml Structure:
<div id="page" class="c">
@{ Html.RenderPartial("_Header.Mobile"); }
@{
Html.RenderPartial("_Error.Mobile", null);
Html.RenderPartial("_Session.Mobile");
}
@RenderBody()
@RenderSection("body")
@{ Html.RenderPartial("_Footer.Mobile"); }
</div>
Body Section of other .Mobile.cshtml
@section body {
@{
var data = new ViewDataDictionary();
data["SelectedPage"] = "Booking";
}
<script>
dojoConfig.addModuleName(
"tui/widget/common/ToolTip",
"tui/widget/forms/view/Textbox",
"tui/widget/forms/view/SubmitForm",
"tui/widget/forms/view/acss/retrieveBooking/RetrieveBookingFormController",
"tui/widget/forms/view/acss/retrieveBooking/DateDropdown",
"tui/widget/forms/view/acss/retrieveBooking/MonthYearDropdown"
);
</script>
<div id="content">
<div class="content-width">
<div id="customer-form" class="acss">
<div class="retrieve-booking" id="retrieveBookingForm" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.RetrieveBookingFormController" data-dojo-props="error:null">
@using (Html.BeginForm("Retrieve", "Booking", FormMethod.Post, new { id = formId }))
{
<div class="section-heading branding first">
<h2>Find your booking</h2>
</div>
<p class="intro">To Select your Seats and Add Extras please enter your booking information below.</p>
<p class="do-online"><i class="caret link blue"></i><a href="#side-panel">What can you do online?</a></p>
<div id="RecordLocator" class="row with-info c" data-dojo-type="tui.widget.forms.view.Textbox" data-dojo-props="form: 'retrieveBookingForm', message:'Please enter the correct booking number, as shown in your booking confirmation or ticket e.g. 12345.'">
@Html.Nca().LabelFor(m => m.RecordLocator, Resource.String("BookingNumber"))
<input type="number" id="retrieveBooking_RecordLocator" name="retrieveBooking.RecordLocator" pattern="[0-9]*" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="error">
<i class="caret erase red"></i>
<i class="caret tick green"></i>
<div class="tip-container c">
<a href="javascript:void(0)" data-dojo-type="tui.widget.common.ToolTip" data-dojo-props="text:'Please enter your booking number as shown in your booking confirmation or ticket, e.g. 12345', position: 'top center'">
<i class="caret info blue"></i>
</a>
</div>
<span class="message hide">Please enter the correct booking number, as shown in your booking confirmation or ticket e.g. 12345.</span>
</div>
<div id="LastName" class="row with-info c" data-dojo-type="tui.widget.forms.view.Textbox" data-dojo-props="form: 'retrieveBookingForm', message:'Please enter the correct lead passenger surname as it appears in your booking confirmation or ticket.'">
<label for="surname" class="two-lines mob-one-line">Surname <span class="hint">(Lead passenger)</span></label>
<input id="retrieveBooking_LastName" class="error" value="" type="text" name="retrieveBooking.LastName" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<i class="caret erase red"></i>
<i class="caret tick green"></i>
<div class="tip-container c">
<a href="javascript:void(0)" data-dojo-type="tui.widget.common.ToolTip" data-dojo-props="text:'Please enter the lead passenger surname as it appears on your booking confirmation or ticket, e.g. if John Smith enter SMITH. If there are spaces, hyphens, apostrophes or other special characters in your name, please try again without these. For example ONEILL not O’NEILL, STJOHN not ST JOHN.', position: 'top center'">
<i class="caret info blue"></i>
</a>
</div>
<span class="message hide">Please enter the correct lead passenger surname as it appears in your booking confirmation or ticket.</span>
</div>
var daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
var today = DateTime.Now.Day;
var currentMonthAndYear = String.Concat(DateTime.Now.Year, "/", DateTime.Now.Month); ;
var monthList = GetDateResourceList();
<div class="row with-info c">
<label class="b">Travel date</label>
<div class="select" id ="travelDay" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.DateDropdown" data-dojo-props='data:{"days":@daysInMonth,"selectedData": @DateTime.Now.Day}'>
<span class="text" id="hiddenDayText"></span>
<span class="arrow"><span></span></span>
<select id="selectedDay"></select>
<input type="hidden" id="hiddenDay" />
</div>
<div class="select" id ="travelMonthYear" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.MonthYearDropdown" data-dojo-props='data:{"monthYears":@Html.Raw(Json.Encode(monthList.SelectList())) ,"selectedData": "@currentMonthAndYear"}'>
<span class="text"></span>
<span class="arrow"><span></span></span>
<select id="selectedMonthYear"></select>
<input type="hidden" id="hiddenMonthYear" />
</div>
@Html.Nca().Hidden("FlightDate", DateTime.Now.Date, new { id = "hiddenFlightDate" })
<i class="caret erase red"></i>
<i class="caret tick green"></i>
</div>
<div class="row with-info button-align last c">
<input type="submit" class="button cta b" value="@Resource.String("FindBooking")" id="FindBooking"
data-dojo-type="tui.widget.forms.view.SubmitForm" data-dojo-props="form: 'retrieveBookingForm'"/>
</div>
}
</div>
</div>
@{Html.RenderPartial("_BenefitsTable.Mobile");}
</div>
</div>
}
Did you encounter this issue anytime? If so, please suggest.
Thanks,
Sandeep
I am using .NET API of WURFL for Mobile detection. Device detection is not working fine some times. Mobile site shows desktop views. Issue is with body part that loads desktop view. Header & Footer shows Mobile.
I am using the WURFL version 1.5.1.0.
Global.asax.cs
protected override void Application_Start()
{
base.Application_Start();
BundleConfig.RegisterBundles(BundleTable.Bundles);
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
ModelBinders.Binders.Add(typeof(DateTime), new ShortLittleEndianDateBinder());
ModelBinders.Binders.Add(typeof(DateTime?), new ShortLittleEndianDateBinder());
LoadWurflData(Context);
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
{
ContextCondition = (context =>
{
var manager = (context.Cache[WurflManagerCacheKey] as IWURFLManager);
if (manager == null)
{
var server = Context.Server;
var appSettings = WebConfigurationManager.AppSettings;
var wurflDataFile = appSettings["WurflDataFilePath"];
var wurflPatchFile = appSettings["WurflPatchFilePath"];
var configurer = new InMemoryConfigurer()
.MainFile(wurflDataFile)
.PatchFile(wurflPatchFile);
manager = WURFLManagerBuilder.Build(configurer);
}
var cabablities = manager.GetDeviceForRequest(context.Request.UserAgent);
return cabablities.GetCapability("is_wireless_device") == "true";
//return cabablities.GetCapability("mobile_browser").Contains("Opera");
//return cabablities.UserAgent.Contains("Opera");
})
});
}
public static void LoadWurflData(HttpContext context)
{
var server = context.Server;
var appSettings = WebConfigurationManager.AppSettings;
var wurflDataFile = appSettings["WurflDataFilePath"];
var wurflPatchFile = appSettings["WurflPatchFilePath"];
var configurer = new InMemoryConfigurer()
.MainFile(wurflDataFile)
.PatchFile(wurflPatchFile);
var manager = WURFLManagerBuilder.Build(configurer);
context.Cache[WurflManagerCacheKey] = manager;
}
Layout.Mobile.cshtml Structure:
<div id="page" class="c">
@{ Html.RenderPartial("_Header.Mobile"); }
@{
Html.RenderPartial("_Error.Mobile", null);
Html.RenderPartial("_Session.Mobile");
}
@RenderBody()
@RenderSection("body")
@{ Html.RenderPartial("_Footer.Mobile"); }
</div>
Body Section of other .Mobile.cshtml
@section body {
@{
var data = new ViewDataDictionary();
data["SelectedPage"] = "Booking";
}
<script>
dojoConfig.addModuleName(
"tui/widget/common/ToolTip",
"tui/widget/forms/view/Textbox",
"tui/widget/forms/view/SubmitForm",
"tui/widget/forms/view/acss/retrieveBooking/RetrieveBookingFormController",
"tui/widget/forms/view/acss/retrieveBooking/DateDropdown",
"tui/widget/forms/view/acss/retrieveBooking/MonthYearDropdown"
);
</script>
<div id="content">
<div class="content-width">
<div id="customer-form" class="acss">
<div class="retrieve-booking" id="retrieveBookingForm" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.RetrieveBookingFormController" data-dojo-props="error:null">
@using (Html.BeginForm("Retrieve", "Booking", FormMethod.Post, new { id = formId }))
{
<div class="section-heading branding first">
<h2>Find your booking</h2>
</div>
<p class="intro">To Select your Seats and Add Extras please enter your booking information below.</p>
<p class="do-online"><i class="caret link blue"></i><a href="#side-panel">What can you do online?</a></p>
<div id="RecordLocator" class="row with-info c" data-dojo-type="tui.widget.forms.view.Textbox" data-dojo-props="form: 'retrieveBookingForm', message:'Please enter the correct booking number, as shown in your booking confirmation or ticket e.g. 12345.'">
@Html.Nca().LabelFor(m => m.RecordLocator, Resource.String("BookingNumber"))
<input type="number" id="retrieveBooking_RecordLocator" name="retrieveBooking.RecordLocator" pattern="[0-9]*" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="error">
<i class="caret erase red"></i>
<i class="caret tick green"></i>
<div class="tip-container c">
<a href="javascript:void(0)" data-dojo-type="tui.widget.common.ToolTip" data-dojo-props="text:'Please enter your booking number as shown in your booking confirmation or ticket, e.g. 12345', position: 'top center'">
<i class="caret info blue"></i>
</a>
</div>
<span class="message hide">Please enter the correct booking number, as shown in your booking confirmation or ticket e.g. 12345.</span>
</div>
<div id="LastName" class="row with-info c" data-dojo-type="tui.widget.forms.view.Textbox" data-dojo-props="form: 'retrieveBookingForm', message:'Please enter the correct lead passenger surname as it appears in your booking confirmation or ticket.'">
<label for="surname" class="two-lines mob-one-line">Surname <span class="hint">(Lead passenger)</span></label>
<input id="retrieveBooking_LastName" class="error" value="" type="text" name="retrieveBooking.LastName" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<i class="caret erase red"></i>
<i class="caret tick green"></i>
<div class="tip-container c">
<a href="javascript:void(0)" data-dojo-type="tui.widget.common.ToolTip" data-dojo-props="text:'Please enter the lead passenger surname as it appears on your booking confirmation or ticket, e.g. if John Smith enter SMITH. If there are spaces, hyphens, apostrophes or other special characters in your name, please try again without these. For example ONEILL not O’NEILL, STJOHN not ST JOHN.', position: 'top center'">
<i class="caret info blue"></i>
</a>
</div>
<span class="message hide">Please enter the correct lead passenger surname as it appears in your booking confirmation or ticket.</span>
</div>
var daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
var today = DateTime.Now.Day;
var currentMonthAndYear = String.Concat(DateTime.Now.Year, "/", DateTime.Now.Month); ;
var monthList = GetDateResourceList();
<div class="row with-info c">
<label class="b">Travel date</label>
<div class="select" id ="travelDay" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.DateDropdown" data-dojo-props='data:{"days":@daysInMonth,"selectedData": @DateTime.Now.Day}'>
<span class="text" id="hiddenDayText"></span>
<span class="arrow"><span></span></span>
<select id="selectedDay"></select>
<input type="hidden" id="hiddenDay" />
</div>
<div class="select" id ="travelMonthYear" data-dojo-type="tui.widget.forms.view.acss.retrieveBooking.MonthYearDropdown" data-dojo-props='data:{"monthYears":@Html.Raw(Json.Encode(monthList.SelectList())) ,"selectedData": "@currentMonthAndYear"}'>
<span class="text"></span>
<span class="arrow"><span></span></span>
<select id="selectedMonthYear"></select>
<input type="hidden" id="hiddenMonthYear" />
</div>
@Html.Nca().Hidden("FlightDate", DateTime.Now.Date, new { id = "hiddenFlightDate" })
<i class="caret erase red"></i>
<i class="caret tick green"></i>
</div>
<div class="row with-info button-align last c">
<input type="submit" class="button cta b" value="@Resource.String("FindBooking")" id="FindBooking"
data-dojo-type="tui.widget.forms.view.SubmitForm" data-dojo-props="form: 'retrieveBookingForm'"/>
</div>
}
</div>
</div>
@{Html.RenderPartial("_BenefitsTable.Mobile");}
</div>
</div>
}
Did you encounter this issue anytime? If so, please suggest.
Thanks,
Sandeep