Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i detect if the request is coming from a mobile browser in my asp.net MVC 3

Tags:

what i am trying to achieve is simple; Among all the view which i have in my web application, i have only two razor views that i have created a mobile version for them. so i need to redirect the users to these views if they are accessing the application from their mobile devices. i tried the following on the controller level but it did not redirect the users when i run my test on different mobile devices :-

if (Request.Browser.IsMobileDevice)             {                 return View("MobileStudentStartAssessment");             }             else {                 return View("StudentStartAssessment");             } 

So is there another approach that i can follow which can detect most of the mobile devices? Thanks

like image 775
qalife4ever Avatar asked Aug 12 '11 01:08

qalife4ever


People also ask

How can I view my ASP.NET website on mobile devices?

Put your mobile device in your lan and then type http://<ip adresse of the host computer>/<name of the website> into adress bar from browser on your mobile device.

How does ASP.NET handle requests?

ASP.NET is a request processing engine. It takes an incoming request and passes it through its internal pipeline to an end point where you as a developer can attach code to process that request. This engine is actually completely separated from HTTP or the Web server.

What is request in ASP NET MVC?

Requests to an ASP.NET MVC-based Web application first pass through the UrlRoutingModule object, which is an HTTP module. This module parses the request and performs route selection. The UrlRoutingModule object selects the first route object that matches the current request.


1 Answers

You can use the Request.Browser.IsMobileDevice property.

like image 164
BFree Avatar answered Sep 28 '22 00:09

BFree