引用“路由"类型声称它是在"System.web"中定义的 [英] Reference to Type 'Route' claims it is defined in 'System.web'

查看:104
本文介绍了引用“路由"类型声称它是在"System.web"中定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中添加一个区域,但会在

I am trying to add a area to my application but it throws the below error at

context.MapRoute

context.MapRoute

我的应用程序中引用了system.web和system.web.mvc dll.可能是什么问题?

I have system.web and system.web.mvc dlls referred in my application. What may be the issue?

我的应用程序的目标是.Net core 2.0

My application is targeting .Net core 2.0

请问任何指针?

推荐答案

如果您要将Projecto定位于.Net Core 2.0,并且它是ASP.NET Core,则应遵循

If you're targeting your projecto to .Net core 2.0 and it's a ASP.NET Core, than you should follow these instructions on microsoft docs. You don't need those references to System.Web.

例如,您可以在启动类中使用MapRoute进行区域注册,然后文件夹/文件结构将完成其余工作:

You can do area registration with MapRoute in your startup class for example, and the folder/file structure will do the rest:

...
   app.UseMvc(routes =>
   {
     routes.MapRoute(
         name: "areaRoute",
         template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

     routes.MapRoute(
         name: "default",
         template: "{controller=Home}/{action=Index}/{id?}");
   });

这篇关于引用“路由"类型声称它是在"System.web"中定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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