WURFL in ASP .Net 4.0

plutomobile
Posts: 11
Joined: Fri Aug 08, 2014 2:13 am

WURFL in ASP .Net 4.0

Postby plutomobile » Fri Aug 08, 2014 4:45 am

Hi,

we got the code in mvc 4.0, but we are using ASP .Net 4.0, So please can anyone help me to change the code to ASP .Net 4.0

support-all
Posts: 32
Joined: Mon Oct 08, 2012 2:47 am

Re: WURFL in ASP .Net 4.0

Postby support-all » Fri Aug 08, 2014 11:13 am

Hi,
WURFL API makes no difference between ASP.NET Web Forms and ASP.NET MVC.
You can use the code snippet in http://wurfl.sourceforge.net/dotnet_index.php to test it.

For example, in order to print simply the user_agent of a browser, you have to modify the Global.asax.cs Class like this:

Code: Select all

public class Global : HttpApplication
    {
        public const String WurflDataFilePath = "~/App_Data/wurfl-latest.zip";
        public const String WurflPatchFilePath = "~/App_Data/web_browsers_patch.xml";
        private void Application_Start(Object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
            var wurflPatchFile = HttpContext.Current.Server.MapPath(WurflPatchFilePath);
            var configurer = new InMemoryConfigurer().MainFile(wurflDataFile).SetMatchMode(MatchMode.Accuracy);
            var manager = WURFLManagerBuilder.Build(configurer);
      
        }
}
And, finally, add the following entry in your Default.aspx

Code: Select all

<p>USER AGENT: <%:WURFLManagerBuilder.Instance.GetDeviceForRequest(new WURFLRequest(Request.UserAgent)).Id %></p>
Regards

Beppe

plutomobile
Posts: 11
Joined: Fri Aug 08, 2014 2:13 am

Re: WURFL in ASP .Net 4.0

Postby plutomobile » Sat Aug 09, 2014 1:02 am

hi,

The code which you send, i have copied and paste in my application.
It throws some errors.

1) where i will get the wurfl-latest.zip file and web_browsers_patch.xml
2) what i have to add in my web.config file.
3) All these classes throws error
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterOpenAuth();
RouteConfig.RegisterRoutes(RouteTable.Routes);

Please help me regarding this.

support-all
Posts: 32
Joined: Mon Oct 08, 2012 2:47 am

Re: WURFL in ASP .Net 4.0

Postby support-all » Mon Aug 11, 2014 4:54 am

Hi,

A default ASP.Net web application include AuthConfig.RegisterOpenAuth() and RouteConfig.RegisterRoutes(RouteTable.Routes) methods on Application_Start.
Web_browsers_patch is no longer needed, so you can remove it.
If you install WURFL API for .NET package by using NUGET, the wurfl-latest.zip is copied in App_Data folder in your project by default. You can change the file location but you have to modify the Web.config adding the file path you've chosen:

Code: Select all

<!-- Note about WURFL config
       You can use the root operator (~) to refer to a virtual path. -->
  <wurfl mode="Accuracy">
    <mainFile path="~/YourPath/wurfl-latest.zip" />
  </wurfl></configuration>
To recap:
- Modify the Global.asax.cs class like this:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using WebApplication2;
using WURFL;
using WURFL.Config;

namespace WebApplication2
{
    public class Global : HttpApplication
    {
        public const String WurflDataFilePath = "~/App_Data/wurfl-latest.zip";
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AuthConfig.RegisterOpenAuth();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
            var configurer = new InMemoryConfigurer().MainFile(wurflDataFile).SetMatchMode(MatchMode.Accuracy);
            var manager = WURFLManagerBuilder.Build(configurer);
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }
    }
}
And, finally, add the following entries in your Default.aspx
At the beginning

Code: Select all

<%@ Import Namespace="WURFL" %>
<%@ Import Namespace="WURFL.Request" %>
<%@ Import Namespace="System.Linq" %>
and then

Code: Select all

<p>USER AGENT: <%:WURFLManagerBuilder.Instance.GetDeviceForRequest(new WURFLRequest(Request.UserAgent)).Id %></p>

in the asp:Content to print the user agent on a browser.

Let us know if it will be ok.

Regards

Beppe


Who is online

Users browsing this forum: No registered users and 1 guest