【发布时间】:2014-03-19 09:45:31
【问题描述】:
几天前我构建了一个 .NET MVC4 应用程序。 MVC4 体验中的路由模块非常棒和优雅,我想将其中一个功能实现到我自己的现有项目中。
它是纯 asp.net 4.0 网络项目。
Web 应用程序由纯 HTML 作为视图、许多 javascript 和 jquery 插件作为控制器以及几个 Web 服务组成。
它通过 Ajax 与服务器、数据库和 Web 服务通信。
每次尝试调用 Web 服务中的方法时,我都必须使用 Ajax,我已经受够了。
但是到目前为止,在应用中实现路由模块还没有奏效。
我在开头创建了Global.asax 来使用路由功能,如下所示。
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
并声明RegisterRoutes方法如下。
void RegisterRoutes(RouteCollection routes)
{
//routes.MapRoute(
// name: "loginController",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "login", action = "Index", id = UrlParameter.Optional }
//);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
"loginController",
"{controller}/{action}/{id}",
"~/Controller/loginController.cs");
}
并像这样创建和编码loginController。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
public class loginController : Controller
{
public string index(int id)
{
return "works fine";
}
}
试试这个网址" http://localhost:52749/login/index/1 "
然后它会抛出这个错误页面。
'/' 응용 프로그램에 서버 오류가 있습니다.
경로 처리기 'System.Web.Routing.PageRouteHandler'의 GetHttpHandler() 메서드에서 IHttpHandler를 반환하지 않았습니다.
설명: 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 스택 추적을 검토하여 발생한 오류 및 코드에서 오류가 발생한 위치에 대한 자세한 정보를 확인하십시오.
예외 정보: System.InvalidOperationException: 경로 처리기 'System.Web.Routing.PageRouteHandler'의 GetHttpHandler() 메서드에서 IHttpHandler를 반환하지 않았습니다.
소스 오류:
현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 생성되었습니다. 아래의 예외 스택 추적을 사용하여 예외의 원인 및 위치 정보를 확인할 수 있습니다.
스택 추적:
[InvalidOperationException: 경로 처리기 'System.Web.Routing.PageRouteHandler'의 GetHttpHandler() 메서드에서 IHttpHandler를 반환하지 않았습니다.]
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9599531
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
我很抱歉用韩语展示这个。
简而言之,就是GetHttpHandler() Method didn't return IHttpHandler.
我已经尝试用谷歌搜索,但没有找到任何线索。
谁能帮我摆脱困境?
【问题讨论】:
-
当您说“纯 ASP .NET”时,您是指 Web 表单吗?
-
是的。仅供参考,在这里使用 aspx 是非常有限的。没有一个用于页面。我只使用 aspx 作为服务。
标签: c# jquery .net asp.net-mvc asp.net-mvc-4