asp.net-mvc – 没有找到与名为“User”的控制器匹配的类型
发布时间:2020-05-23 11:16:00 所属栏目:asp.Net 来源:互联网
导读:我正在尝试浏览到其网址为以下格式的网页: localhost:xxxxx / User / {id} / VerifyEmail?secretKey = xxxxxxxxxxxxxxx 我在RouteConfig.cs文件中添加了一条新路由,因此我的RouteConfig.cs如下所示: public class RouteConfig{ public static void Regis
|
我正在尝试浏览到其网址为以下格式的网页:
我在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();
}
}
请告诉我我做错了什么? 解决方法在我花了几乎30分钟尝试解决这个问题的时候,我发现是什么原因造成的:我在WebApiConfig.cs中定义的路由是这样的: 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中定义的标准路由。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用逗号分隔值搜索列
- asp.net-mvc – 如何锁定ASP.NET MVC中的路径?
- asp.net-mvc-3 – 具有ASP.NET MVC3和嵌入式Razor视图的插件
- asp.net-mvc – 命中错误:在解析器和自定义注册提供程序中
- asp.net-mvc – 如何在Visual Studio 2008和ASP.Net MVC中编
- asp.net-mvc – 如何使用ASP.NET MVC 5和OWIN获取Facebook的
- asp.net-mvc – 如何降级Visual Studio 2012中的Entity Fra
- 会员资格,SimpleMembership,ASP.NET身份之间有什么区别?
- asp.net-mvc-3 – 剃刀引擎 – SEO元标签
- asp.net-mvc – 如何在MVC3中的局部视图中渲染节?
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC Session vs Global
- asp.net – Xamarin.Forms应用程序SQL服务器数据
- 如何调试asp.net mvc 4源代码?
- asp.net-mvc – 部分视图中的Razor部分包含
- asp.net-mvc-3 – 提交后的mvc3复选框值
- asp.net – 在IIS上运行Python和Django
- asp.net – MVC 3在IEnumerable模型视图中编辑数
- asp.net-mvc-3 – 默认模型绑定器没有绑定到字段
- 如何在ASP.NET Membership Cookie中存储自定义数
- asp.net-mvc – 在MVC ASP.NET中使用/显示RSS源的
热点阅读
