热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP.global_asax不存在于命名空间ASP中的问题

本文讨论了在ASP中创建RazorFunctions.cshtml文件时出现的问题,即ASP.global_asax不存在于命名空间ASP中。文章提供了解决该问题的代码示例,并详细解释了代码中涉及的关键概念,如HttpContext、Request和RouteData等。通过阅读本文,读者可以了解如何解决该问题并理解相关的ASP概念。

I created a RazorFunctions.cshtml file on App_Code

我创建了一个RazorFunctions。cshtml文件App_Code

@functions {
    public static string GetActiveClassIf(string controllerName, string actiOnName= null)
    {
        var routeData = @HttpContext.Current.Request.RequestContext.RouteData;
        string currentCOntroller= routeData.Values["controller"].ToString();
        string currentAction = routeData.Values["action"].ToString();
        return cOntrollerName== currentController &&
            (String.IsNullOrEmpty(actionName) || currentAction == actionName) ? "active" : "";
    }
}

and when I compile, it give me 2 errors (compilation get success and site work without problem) but the errors are annoying.

当我编译时,它会给我两个错误(编译获得成功,站点工作没有问题),但是这些错误很烦人。

The RazorFunctions.cshtml are as Content (tried compile but doesn't work with cshtml files of course)

RazorFunctions。cshtml是作为内容的(尝试编译,但当然不能使用cshtml文件)

Global.asax.cs is :

Global.asax。cs是:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        ModelMetadataConfig.RegisterModelMetadata();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Database.SetInitializer(new MigrateDatabaseToLatestVersion());
        //Database.SetInitializer(new DropCreateDatabaseAlways());
    }
}

and

<%@ Application Codebehind="Global.asax.cs" Inherits="Bouron.Web.MvcApplication" Language="C#" %>

This is the first time I use the App_Code so I don't know what else to do, all search returns ASP.NET 1-2 results, are out of date where razor doesn't even exist so I'm not sure how can I solve this.

这是我第一次使用App_Code,所以我不知道还能做什么,所有的搜索返回ASP。NET 1-2的结果,已经过时了,而razor根本不存在,所以我不知道该怎么解决这个问题。

I'm using Visual Studio 2015 (just in case it matters)

我使用的是Visual Studio 2015(以防万一)

8 个解决方案

#1


43  

After further investigation I found that this is a known issue.

经过进一步调查,我发现这是一个已知的问题。

source: https://support.microsoft.com/en-us/kb/3025133

来源:https://support.microsoft.com/en-us/kb/3025133

ASP.NET and Web Development

ASP。网和Web开发

  • When you create a Web Forms 4.5 WAP and open a Web Form page, you receive the following errors in the Errors List window:

    当您创建一个Web Forms 4.5 WAP并打开一个Web表单页面时,您会在error List窗口中收到以下错误:

  • The project will run without any issues. Error CS0234 The type or namespace name 'global_asax' does not exist in the namespace 'ASP' (are you missing an assembly reference?) Error CS0234 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) Assume that you use new language features for C# and VB in Visual Studio 2015 RC. You receive a runtime error when you use C# or VB in a Web Form page or in Razor Views.

    这个项目将不会出现任何问题。在名称空间“ASP”中不存在类型或名称空间名称“global_asax”(您是否缺少一个程序集引用?)错误CS0234名称空间“System”中不存在类型或名称空间名称“Linq”(是否缺少一个程序集引用?)假设您在Visual Studio 2015 RC中使用c#和VB的新语言特性。当您在Web表单页面或Razor视图中使用c#或VB时,会收到一个运行时错误。

To work around this issue, install Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package. This package will substitute the Roslyn-based provider for the in-box CodeDom providers for ASP.NET.

要解决这个问题,请安装microsoft.codedom . provider。DotNetCompilerPlatform NuGet包。这个包将用基于罗斯林的提供程序代替ASP.NET的收件箱代码dom提供程序。

#2


19  

I had the same issue.

我也有同样的问题。

I manually edited the generated file file.cshtml.72cecc2a.cs (it was at AppData\Local\Temp\Temporary ASP.NET Files\root) and changed ASP.global_asax to System.Web.HttpApplication and the error went away.

我手动编辑生成的文件file.cshtml.72cecc2a。cs(在AppData\Local\Temp\临时ASP上)。NET文件\root)和更改的ASP。global_asax包含。HttpApplication和错误消失了。

This is the generated code:

这是生成的代码:

protected static ASP.global_asax ApplicationInstance {
    get {
        return ((ASP.global_asax)(Context.ApplicationInstance));
    }
}

I changed it to:

我把它改为:

protected static System.Web.HttpApplication ApplicationInstance {
    get {
        return ((System.Web.HttpApplication)(Context.ApplicationInstance));
    }
}

I don't know why this is happening though.

我不知道为什么会这样。

#3


14  

I've found that if I have the files in App_Code open in Visual Studio 2015 when I run the build, then I don't get the errors. As soon as I close the files the errors show up again.

我发现如果我在运行构建时在Visual Studio 2015中打开App_Code中的文件,那么我不会得到错误。我一关闭文件,错误就会再次出现。

#4


2  

After trying a variety of the solutions proposed here, it turns out that simply quitting Visual Studio 2015 and then restarting it was enough to get the Solution/Project to successfully compile once again.

在尝试了本文提出的各种解决方案之后,我们发现,仅仅退出Visual Studio 2015,然后重新启动就足以让解决方案/项目再次成功编译。

#5


1  

Two things i did to resolve this was to re-target the framework and then changing it back (was using 4.5.1 changed it to 4.5 and back)

我做了两件事来解决这个问题,就是重新定位框架,然后将其修改(使用4.5.1将其更改为4.5和back)

After this i had a lot of error with T4MVC which i was also using, i upgraded it to newest version but i could see that in source control that T4MVC was installed targeting framework 4.5 and when you re/install a new nuget package it changes the target framework, so that was changed to 4.5.1

这之后我有很多错误T4MVC我也用,我升级到最新版本,但我可以看到,在源代码控制T4MVC安装针对framework 4.5和当你/安装一个新的nuget包它改变了目标框架,这是改为4.5.1

After this everything worked. I didn't test if you only need to do that second part of this answer, but i would try that first.

在这之后一切工作。我没有测试你是否只需要做这个答案的第二部分,但我会先做那个。

#6


0  

The way I resolved this error was to move my code form Global.asax.cs into Startup.cs and delete Global.asax so that there aren't any codebehind files in my project. See this question for more info.

我解决这个错误的方法是将我的代码从Global.asax移走。cs启动。cs和删除全球。asax使我的项目中没有任何代码。更多信息请参见这个问题。

#7


0  

I installed Microsoft.CodeDom.Providers.DotNetCompilerPlatform for my web project and then removed the package. The error went away.

我Microsoft.CodeDom.Providers安装。我的web项目的dotnetcompile erplatform,然后删除这个包。错误的走了。

#8


-2  

Code placed in App_Code folder is treated a bit different, it is compiled at runtime. cshtml file is 'Content' so that could be the reason why you get errors. Create normal folder within your project name it Code or something similar (but not App_Code) and place your file there.

放置在App_Code文件夹中的代码被处理得有点不同,它是在运行时编译的。cshtml文件是“内容”,因此这可能是您出现错误的原因。在您的项目名称中创建普通文件夹,或者类似的(但不是App_Code),并将文件放在那里。


推荐阅读
author-avatar
手机用户2502912857
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有