[英]Global.asax.cs name 'RouteConfig' does not exist in the current context
there are three files in my solution which I think I referencing but I am stuck with these 3 errors 我的解决方案中有三个文件,我认为我要引用,但是我被这三个错误所困扰
Global.asax.cs name 'RouteConfig' does not exist in the current context Global.asax.cs名称“ RouteConfig”在当前上下文中不存在
What am I missing ? 我想念什么? thanks:) 谢谢:)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Http;
namespace PingYourPackage.API.WebHost
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
var config = GlobalConfiguration.Configuration;
RouteConfig.RegisterRoutes(config);
WebAPIConfig.Configure(config);
AutofacWebAPI.Initialize(config);
}
***************
here is the class autofac 这是class autofac
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Autofac;
using Autofac.Integration.WebApi;
using System.Reflection;
namespace PingYourPackage.Config
{
public class AutofacWebAPI
{
public static void Initialize(HttpConfiguration config)
{
Initialize(config,
RegisterServices(new ContainerBuilder()));
}
public static void Initialize (
HttpConfiguration config, IContainer container)
{
config.DependencyResolver =
new AutofacWebApiDependencyResolver(container);
}
private static IContainer RegisterServices(ContainerBuilder builder)
{
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// registeration goes here
return builder.Build();
}
}
}
When you generate a new project, these *Config
classes (eg RouteConfig
) are put in App_Code
by default. 生成新项目时,默认情况下,这些*Config
类(例如RouteConfig
)被放入App_Code
。
It looks like you moved the *Config
classes out from the App_Code
directory, into a Config
directory. 看起来您已将*Config
类从App_Code
目录移出到Config
目录中。 Everything in App_Code
is automatically referenced by other code in your project. 项目中的其他代码会自动引用App_Code
中的所有内容。
https://msdn.microsoft.com/en-us/library/ex526337(v=vs.140).aspx https://msdn.microsoft.com/en-us/library/ex526337(v=vs.140).aspx
Code in the
App_Code
folder is referenced automatically in your application.App_Code
文件夹中的代码在您的应用程序中被自动引用。
It is okay that you moved them, they can live anywhere. 没关系,您可以移动它们,它们可以住在任何地方。 Now, you just need to reference them manually inside your Global.asax.cs
file. 现在,您只需要在Global.asax.cs
文件中手动引用它们即可。
using PingYourPackage.Config;
(assuming PingYourPackage
is the name of your project/root namespace) (假设PingYourPackage
是您的项目/根名称空间的名称)
也可以通过在App_Start文件夹中添加RouteConfig.cs类来解决此问题。
I added using System.Web.Routing;
我using System.Web.Routing;
添加using System.Web.Routing;
to my code, and worked for me! 对我的代码,并为我工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.