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
WURFL in ASP .Net 4.0
-
- Posts: 32
- Joined: Mon Oct 08, 2012 2:47 am
Re: WURFL in ASP .Net 4.0
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:
And, finally, add the following entry in your Default.aspx
Regards
Beppe
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);
}
}
Code: Select all
<p>USER AGENT: <%:WURFLManagerBuilder.Instance.GetDeviceForRequest(new WURFLRequest(Request.UserAgent)).Id %></p>
Beppe
-
- Posts: 11
- Joined: Fri Aug 08, 2014 2:13 am
Re: WURFL in ASP .Net 4.0
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.
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.
-
- Posts: 32
- Joined: Mon Oct 08, 2012 2:47 am
Re: WURFL in ASP .Net 4.0
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:
To recap:
- Modify the Global.asax.cs class like this:
And, finally, add the following entries in your Default.aspx
At the beginning
and then
in the asp:Content to print the user agent on a browser.
Let us know if it will be ok.
Regards
Beppe
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>
- 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
}
}
}
At the beginning
Code: Select all
<%@ Import Namespace="WURFL" %>
<%@ Import Namespace="WURFL.Request" %>
<%@ Import Namespace="System.Linq" %>
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