Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the Request.Browser.IsMobileDevice property.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...