使用 51Degrees.mobi 重定向到 MVC 移动区域时出错
我是 MVC 的新手。我编写的应用程序可以运行,并且我会在学习过程中不断对其进行微调。最近,我一直在玩弄移动网站工具。我从来不需要这样做,所以我尽可能多地搜索/阅读/修补。我从 Microsoft Web App Toolkit 开始,它最终有点过时了,所以我继续阅读并最终转而使用 51Degrees.mobi 库。
我根据几个不同的帖子进行了设置:
- Steve Sanderson - http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
- 51Degrees 用户指南 - http://51 Degrees.codeplex.com/wikipage?title=User%20guide< /a>
- ...以及许多其他网站和描述都围绕相同的基本点。
这就是桑德森先生所描述的。
- 为我的移动控制器/视图创建了一个 MVC 区域,进而创建了 MobileAreaRegistration.cs 文件
- 修改了 MobileAreaRegistration。该区域下的 cs 指定默认控制器和操作。
- 在我的配置文件中包含 51Degrees 组件。即sectionGroup 引用、包含重定向和httpModule 的fythOne 部分。
即使我使用的是 Win7,我也必须使用以下 IIS 模块进行调试:
我还对 Global.asax.cs 文件进行了必要的修改以包含主命名空间,以便应用程序不会混淆执行时应默认到哪个区域。 (如史蒂夫桑德森的帖子所述)。
最后,我安装了 iphone 模拟器和 android 模拟器,重定向的代码位于我的 HomeController 中。我还没有针对每种设备的具体信息。我仍在尝试让重定向正确启动。
当我在桌面浏览器中运行该网站(无移动重定向)时,它运行良好。当我使用模拟器(或尝试将桌面浏览器定向到移动网站)时,出现以下错误。这看起来确实很明显(缺少控制器),但它就在那里。那么我没有看到什么?
找不到请求的页面。 (404)
System.Web.HttpException:找不到路径“/Mobile”的控制器或未实现 IController。在System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext,类型controllerType)在System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext,字符串controllerName)在System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext,IController&amp;控制器、IControllerFactory&工厂)在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)在System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback回调,对象状态)在System.Web .Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) 在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep (IExecutionStep 步骤,Boolean&completedSynchronously)
第二组眼睛会很壮观!预先感谢您的帮助。
I'm a relative newbie to MVC. The app that I've written works and I continually fine tune it as I learn. Recently, I've been toying with mobile web site tools. I've never needed to do this so I did as much searching/reading/tinkering as I could. I started with the Microsoft Web App Toolkit which ended up being a bit outdated so I kept on reading and eventually switched to using the 51Degrees.mobi library.
I've set it up based on several different posts:
- Steve Sanderson - http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
- 51Degrees User Guide - http://51degrees.codeplex.com/wikipage?title=User%20guide
- ...and a bunch of other sites and descriptions all centering around the same basic points.
So here's what I have as described by Mr. Sanderson.
- Created an MVC Area for my Mobile controllers/views which in turn created the MobileAreaRegistration.cs file
- Modified the MobileAreaRegistration.cs under that area to specify the default controller and action.
- Included the 51Degrees components in my config file. Namely the sectionGroup references, the fiftyOne section to include the redirect and the httpModule.
I have to use the following IIS module for debugging even though I'm using Win7:
I've also made the necessary modification to the Global.asax.cs file to include the primary namespace so that there's no confusion for the app as to which area it should default to when executing. (as identified in Steve Sanderson's post).
Lastly, I've installed an iphone emulator and android emulators and the code that redirects is in my HomeController. I don't have anything specific yet for each device. I'm still trying to get the redirect to kick in properly.
When I run the site in the desktop browser (no mobile redirect) it runs fine. When I use the emulators (or try to direct the desktop browser to the mobile site) I get the following error. It sure seems obvious (MISSING CONTROLLER) but it's there. So what am I not seeing?
The requested page cannot be found. (404)
System.Web.HttpException: The controller for path '/Mobile' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
A second set of eyes would be grand! Thanks in advance for the assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了!
问题不在于移动工具和重定向的配置,而在于区域本身的移动部分的命名空间。
我的移动区域控制器中的命名空间是 Licensing.Web.Mobile.Controllers。它们需要是 Licensing.Web.Areas.Mobile.Controllers。
一旦我将“Areas”添加到命名空间中,它就会像冠军一样工作。
我通过更多的挖掘发现了这一点: Asp.NET MVC 2 和 404
Answered!
The issue wasn't with the configuration of the mobile tools and redirection but rather with the namespace of the Mobile section in the Area itself.
My namespaces in my Mobile area controllers were Licensing.Web.Mobile.Controllers. They needed to be Licensing.Web.Areas.Mobile.Controllers.
Once I added "Areas" to the namespace it worked like a champ.
I found this with a bit more digging: Asp.NET MVC 2 and 404