【问题标题】:Why the name 'AuthConfig' does not exist in current context为什么名称“AuthConfig”在当前上下文中不存在
【发布时间】:2014-05-27 15:27:42
【问题描述】:

我的 Global.asax 文件如下所示:

<%@ Application Language="C#" %>
<%@ Import Namespace="WMED" %>
<%@ Import Namespace="System.Web.Optimization" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterOpenAuth();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

</script>

当我第一次运行我的网络应用程序时,我收到了以下错误:

Compiler Error Message: CS0433: The type 'WebSite5.BundleConfig' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\dc09734f\e0cd1143\App_Code.f12uuiuu.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\dc09734f\e0cd1143\assembly\dl3\f6c46402\e43f8fd6_b679cf01\WMEXEC.DLL'

Source Error:

Line 9:      {
Line 10:         // Code that runs on application startup
Line 11:         BundleConfig.RegisterBundles(BundleTable.Bundles);
Line 12:         AuthConfig.RegisterOpenAuth();
Line 13:         RouteConfig.RegisterRoutes(RouteTable.Routes);

我将batch=false 添加到我的Web.config 文件并重新运行Web 应用程序,现在我收到以下错误:

Compiler Error Message: CS0103: The name 'AuthConfig' and 'RouteConfig' does not exist in the current context

Source Error:

Line 10:         // Code that runs on application startup
Line 11:         BundleConfig.RegisterBundles(BundleTable.Bundles);
Line 12:         AuthConfig.RegisterOpenAuth();
Line 13:         RouteConfig.RegisterRoutes(RouteTable.Routes);
Line 14:     }

有问题的两个名称是位于我的 App_Code 文件夹中的 .CS 文件,但我不确定它为什么不起作用。

请帮我解决这个问题。

【问题讨论】:

  • 可能是你导入了WMED命名空间,能去掉吗?
  • 来自 Global.ASAX 文件?
  • 是的,删除&lt;%@ Import Namespace="WMED" %&gt; 行。
  • 我得到了所有三行的CS0103: The name 'BundleConfig' does not exist in the current context
  • 你在上面说When I first ran my web application I received the following error:,回到那个状态,然后删除WMED 引用。

标签: c# asp.net dll


【解决方案1】:

AuthConfig 和 RouteConfig 都是 VS.NET 作为 ASP.NET MVC Web 应用程序项目的一部分生成的类。

AuthConfig 是一个使用 OAuth 提供者进行身份验证的类:http://www.asp.net/mvc/tutorials/security/using-oauth-providers-with-mvc

典型的 RouteConfig 看起来像 https://github.com/shanselman/ASP.NET-MVC-and-DbGeography/blob/master/SpatialFun/App_Start/RouteConfig.cs

如果您将网站项目转换为 Web 应用程序项目,那么您可能需要选择另一种类型的项目 - 非 MVC - ASP.NET WebForms 应用程序。我建议在 VS.NET 中创建一个全新的 webproject 并从那里复制网站上的所有代码。这应该可以解决缺少参考的问题或其他与“网站”相关的问题。

【讨论】:

  • 这不是问题的答案:)
  • 我的文件夹中有两个 .CS 文件。我可以只注释掉这两行,我的网络应用程序应该可以正常工作吗?
  • 我在执行此操作时选择了 ASP.NET 空 Web 应用程序项目,因此它不应该为 MVC 添加任何内容!
  • 由于您的旧项目中没有它们,我认为您可以从新项目中排除两个 .cs 文件并注释掉 AuthConfig.RegisterOpenAuth();和 RouteConfig.RegisterRoutes(RouteTable.Routes);
  • 我在 App_Code 文件夹中有另一个 .CS 文件,它在我的 Default.aspx.cs 文件中被调用...UrgentCareWaitTime urgentcare = new UrgentCareWaitTime();。现在它被复制了,出现了这个错误:Compiler Error Message: CS0433: The type 'UrgentCareWaitTime' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\dc09734f\e0cd1143\App_Code.bfuzwq6h.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\dc09734f\e0cd1143\assembly\dl3\f6c46402\848a6e19_c479cf01\WMEXEC.DLL'
猜你喜欢
  • 1970-01-01
  • 2013-10-02
  • 2014-04-22
  • 2017-06-17
  • 2015-09-11
  • 1970-01-01
  • 1970-01-01
  • 2022-12-18
相关资源
最近更新 更多