没有类型被发现,命名为“用户控制器匹配 [英] No type was found that matches the controller named 'User'

本文介绍了没有类型被发现,命名为“用户控制器匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图导航到一个网页,其中它的URL的格式如下:
本地主机:XXXXX /用户/ {ID} / VerifyEmail SecretKey的= XXXXXXXXXXXXXXX

I'm trying to navigate to a page which its URL is in the following format: localhost:xxxxx/User/{id}/VerifyEmail?secretKey=xxxxxxxxxxxxxxx

我已经添加了 RouteConfig.cs 文件,所以我的 RouteConfig.cs 看起来像一个新的路线这样的:

I've added a new route in the RouteConfig.cs file and so my RouteConfig.cs looks like this:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "VerifyEmail",
            url: "User/{id}/VerifyEmail",
            defaults: new { controller = "User", action = "VerifyEmail" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index",
                id = UrlParameter.Optional }
        );
    }
}

不幸的是,试图导航到该网址时,我得到这个页面:

Unfortunately, when trying to navigate to that URL I get this page:

<Error>
    <Message>
        No HTTP resource was found that matches the request URI 'http://localhost:52684/User/f2acc4d0-2e03-4d72-99b6-9b9b85bd661a/VerifyEmail?secretKey=e9bf3924-681c-4afc-a8b0-3fd58eba93fe'.
    </Message>
    <MessageDetail>
        No type was found that matches the controller named 'User'.
    </MessageDetail>
</Error>

和这里是我的UserController的:

and here is my UserController:

public class UserController : Controller
{

    // GET      /User/{id}/VerifyEmail
    [HttpGet]
    public ActionResult VerifyEmail(string id, string secretKey)
    {
        try
        {
            User user = UsersBL.Instance.Verify(id, secretKey);
            //logger.Debug(String.Format("User %s just signed-in in by email.",
                user.DebugDescription()));
        }
        catch (Exception e)
        {
            throw new Exception("Failed", e);
        }
        return View();
    }
}

请告诉我,我究竟做错了什么?

Please tell me what am I doing wrong?

推荐答案

在我的情况下,花了近30分钟试图来解决这个问题之后,我发现是什么造成的:

In my case after spending almost 30 minutes trying to fix the problem, I found what was causing it:

我的路线是这样的:

config.Routes.MapHttpRoute(
    name: "ControllersApi",
    routeTemplate: "{controller}/{action}"
);

和它应该是这样的:

config.Routes.MapHttpRoute(
    name: "ControllersApi",
     routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }
);

当你看到它是在 RouteConfig.cs 定义的标准路线的干扰。

as you see it was interfering with the standard route defined in RouteConfig.cs.

这篇关于没有类型被发现,命名为“用户控制器匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆