gpt4 book ai didi

asp.net-mvc - 未找到与名为 'User' 的 Controller 匹配的类型

转载 作者:行者123 更新时间:2023-12-03 06:11:26 25 4
gpt4 key购买 nike

我正在尝试导航到其 URL 采用以下格式的页面:本地主机:xxxxx/User/{id}/VerifyEmail?secretKey=xxxxxxxxxxxxxxx

我在 RouteConfig.cs 文件中添加了一条新路由,因此我的 RouteConfig.cs 如下所示:

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

不幸的是,当尝试导航到该 URL 时,我得到了这个页面:

<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:

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

请告诉我我做错了什么?

最佳答案

就我而言, Controller 定义为:

    public class DocumentAPI : ApiController
{
}

将其更改为以下内容有效!

    public class DocumentAPIController : ApiController
{
}

类名必须以Controller结尾!

编辑:正如 @Corey Alix 所建议的,请确保 Controller 具有 public 访问修饰符;非公共(public) Controller 会被路由处理程序忽略!

关于asp.net-mvc - 未找到与名为 'User' 的 Controller 匹配的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com