在纯asp.net,不MVC3 +,调用控制器通过路由方式路由、控制器、方式、asp

2023-09-05 03:32:01 作者:面带微笑的向前走

我前几天内置了.NET MVC4应用。 在MVC4经验路由模块是如此之大,优雅,我想实现的功能之一到我自己的现有项目。

这纯粹是asp.net 4.0 Web项目。

web应用程序是由纯HTML的观点,大量的JavaScript和jQuery插件,控制器,和几个Web服务。

它通过Ajax服务器,数据库和Web服务进行通信。

每一次我尝试在Web服务调用一个方法,我一定要使用Ajax,我受够了。

但是实现路由模块到应用程序并没有工作至今。

我在的Global.asax 来使用路由功能,在一开始,如下。

 无效的Application_Start(对象发件人,EventArgs的)
{
    的RegisterRoutes(RouteTable.Routes);
}
 

和声明的RegisterRoutes 方法如下。

 无效的RegisterRoutes(RouteCollection路由)
{
    //routes.MapRoute(
    //名称:的LoginController
    // URL:{控制器} / {行动} / {ID},
    //默认:新{控制器=登陆,行动=索引,ID = UrlParameter.Optional}
        //);

    routes.IgnoreRoute({}资源个.axd / {* PATHINFO});
    routes.MapPageRoute(
            的LoginController
            {控制器} / {行动} / {ID},
            〜/控制器/ loginController.cs);
}
 

和创建,codeD 的LoginController 是这样的。

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.Mvc;
使用System.Web.Routing;

公共类的LoginController:控制器
{
    公共字符串指数(INT ID)
    {
        回归正常工作;
    }
}
 
mvc3 路由 html,ASP.NET Core 中的MVC路由 二

和给它这个网址的http://本地主机:52749 /登录/指数/ 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上下文)9599531
   System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(对象发件人,EventArgs的)+82
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔和放大器; completedSynchronously)+69
 

我的道歉显示了朝鲜这个。

在坚果壳,它说 GetHttpHandler()方法没有返回的IHttpHandler。

我试图谷歌这一点,并没有选择了一个线索。

任何人可以帮助我摆脱这种??

解决方案

 公共静态无效的RegisterRoutes(RouteCollection路由)
        {
            routes.IgnoreRoute({}资源个.axd / {* PATHINFO});
            routes.MapRoute(
                默认,//路线名称
                {控制器} / {行动} / {ID},// URL与参数
                新{控制器=登录,行动=指数,ID = UrlParameter.Optional} //参数的默认值
            );
                  }
 

你能试试上面?

I built a .NET MVC4 Application a few days ago. The routing module in MVC4 experience was so great and elegant that I would like to implement one of the features into an existing project of my own.

It's pure asp.net 4.0 web project.

The web app is made of pure HTML as view, a lot of javascript and jquery plugins as controllers, and several web services.

It communicates with server, databases, and web services via Ajax.

Every time I try to call a method in a web service, I have to use Ajax, which I had enough.

But implementing routing module into the app hasn't worked so far.

I created Global.asax to use route feature at the beginning as below.

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

and declared RegisterRoutes method as below.

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");
}

and created and coded loginController like this.

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";
    }
}

and give it a shot with this url " http://localhost:52749/login/index/1 " then it throws this error page.

'/' 응용 프로그램에 서버 오류가 있습니다.

경로 처리기 '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

My apologies for showing this in Korean.

in a nut shell, it's saying that GetHttpHandler() Method didn't return IHttpHandler.

I've tried to google this and haven't picked a clue.

Can anybody help me get out of this??

解决方案

 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "login", action = "index", id = UrlParameter.Optional } // Parameter defaults
            );
                  }

can you try above?