Device Detection of WURFL for Mobiles

I have this HTTP request, I expected this, but WURFL is returning that. Please provide enough data to reproduce the problem.
Sandeep
Posts: 3
Joined: Fri Dec 12, 2014 4:14 am

Device Detection of WURFL for Mobiles

Postby Sandeep » 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

Elliotfehr

Re: Device Detection of WURFL for Mobiles

Postby Elliotfehr » Fri Dec 12, 2014 10:58 am

Sandeep,

If I understand correctly, the `Layout.Mobile.cshtml` is being correctly displayed but your mobile views are not being correctly rendered?

Thank you,

Elliot

Sandeep
Posts: 3
Joined: Fri Dec 12, 2014 4:14 am

Re: Device Detection of WURFL for Mobiles

Postby Sandeep » Mon Dec 15, 2014 1:50 am

Yes Elliot, you are absolutely correct.

Layout.Mobile.cshtml(Header & Footer) renders Mobile View but the body part renders desktop view.
I hope Luca Passani has bcc 'ed to you in the mail. I mentioned there with clear screenshots and code as well. Please check.

In the site i am unable to attach the doc's.

Thank you,
Sandeep

Elliotfehr

Re: Device Detection of WURFL for Mobiles

Postby Elliotfehr » Mon Dec 15, 2014 12:33 pm

Sandeep,

I did see the screenshots that were attached. I might recommend setting

Code: Select all

DisplayModeProvider.Instance.RequireConsistentDisplayMode = true;
to try and debug this issue. From what I can see, WURFL is properly detecting the mobile device since your Layout.Mobile.cshtml file is being rendered for these devices. This could be an issue with the naming of the views with the body sections.

Elliot

Sandeep
Posts: 3
Joined: Fri Dec 12, 2014 4:14 am

Re: Device Detection of WURFL for Mobiles

Postby Sandeep » Tue Dec 16, 2014 1:38 am

Elliot,

I added the code in the Application_Start Event of Global.asax. I hope this is the correct way in attaching the code.

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.RequireConsistentDisplayMode = true;

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");
})
});
}

Let me know the speciality of adding this piece of code and how it can be helpful?

In Normal debugging without adding the piece of code given. I got below outputs.

It displays for me 3 display Modes. 1. Mobile 2. Mobile 3. ""(i.e., desktop)

It gives WURFL Info with version property as "((((WURFL.WURFLManager)(manager))._service._deviceRepository).WurflInfo).WurflVersion"
for "WURFL API 1.5.1 release, db.scientiamobile.com - 2014-02-07 18:02:36" and some other stuff.

Note: This Issue persists in the production after 3 to 4 hours. Its not persisting every time.

Please suggest ..

Sandeep

fulvio.crivellaro
Posts: 38
Joined: Tue Jan 31, 2012 10:27 am

Re: Device Detection of WURFL for Mobiles

Postby fulvio.crivellaro » Tue Dec 16, 2014 10:39 am

Hello Sandeep.

As I can see from your code, WURFL query happens only once.
Are you able to verify if one HTTP request may lead to multiple WURFL queries?
.NET documentation here
http://msdn.microsoft.com/en-us/library ... 11%29.aspx
states that
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Can you verify that it is not a synchronization problem?

I have also noticed that some people are complaining about caching issues, still regarding this class.
I can't find any explicit reference in the code snippet that you pasted here that suggests to investigate in this direction, but please consider taking a look at that.

Thanks,
Fulvio


Who is online

Users browsing this forum: No registered users and 7 guests