积极答复者
在ASP.NET MVC4里面怎么判断是否为手机访问

问题
答案
-
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile") { ContextCondition = (ctx => ( (ctx.GetOverriddenUserAgent() != null) && ctx.Request.Browser.IsMobileDevice )) }); }
大家一齊探討、學習和研究,謝謝!
MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
MCT, Microsoft Community Star(TW & HK),
Microsoft MVP for VB.NET since 2003
My MSMVP Blog
請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.- 已建议为答案 Will ShaoMicrosoft employee, Moderator 2015年3月30日 6:19
- 已标记为答案 Will ShaoMicrosoft employee, Moderator 2015年3月30日 6:19
全部回复
-
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile") { ContextCondition = (ctx => ( (ctx.GetOverriddenUserAgent() != null) && ctx.Request.Browser.IsMobileDevice )) }); }
大家一齊探討、學習和研究,謝謝!
MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
MCT, Microsoft Community Star(TW & HK),
Microsoft MVP for VB.NET since 2003
My MSMVP Blog
請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.- 已建议为答案 Will ShaoMicrosoft employee, Moderator 2015年3月30日 6:19
- 已标记为答案 Will ShaoMicrosoft employee, Moderator 2015年3月30日 6:19
-
您好,
你可以使用51Degrees.Mobi Foundation 来检查是否为手机访问:
或者请参考下面的资料:
http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx