热门标签 | 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),并将文件放在那里。


推荐阅读
  • 本文介绍了Sencha Touch的学习使用心得,主要包括搭建项目框架的过程。作者强调了使用MVC模式的重要性,并提供了一个干净的引用示例。文章还介绍了Index.html页面的作用,以及如何通过链接样式表来改变全局风格。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • Asp.net Mvc Framework 七 (Filter及其执行顺序) 的应用示例
    本文介绍了在Asp.net Mvc中应用Filter功能进行登录判断、用户权限控制、输出缓存、防盗链、防蜘蛛、本地化设置等操作的示例,并解释了Filter的执行顺序。通过示例代码,详细说明了如何使用Filter来实现这些功能。 ... [详细]
  • 本文介绍了ASP.NET Core MVC的入门及基础使用教程,根据微软的文档学习,建议阅读英文文档以便更好理解,微软的工具化使用方便且开发速度快。通过vs2017新建项目,可以创建一个基础的ASP.NET网站,也可以实现动态网站开发。ASP.NET MVC框架及其工具简化了开发过程,包括建立业务的数据模型和控制器等步骤。 ... [详细]
  • SpringBoot简单日志配置
     在生产环境中,只打印error级别的错误,在测试环境中,可以调成debugapplication.properties文件##默认使用logbacklogging.level.r ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • C# WPF自定义按钮的方法
    本文介绍了在C# WPF中实现自定义按钮的方法,包括使用图片作为按钮背景、自定义鼠标进入效果、自定义按压效果和自定义禁用效果。通过创建CustomButton.cs类和ButtonStyles.xaml资源文件,设计按钮的Style并添加所需的依赖属性,可以实现自定义按钮的效果。示例代码在ButtonStyles.xaml中给出。 ... [详细]
  • 在springmvc框架中,前台ajax调用方法,对图片批量下载,如何弹出提示保存位置选框?Controller方法 ... [详细]
  • MVC设计模式的介绍和演化过程
    本文介绍了MVC设计模式的基本概念和原理,以及在实际项目中的演化过程。通过分离视图、模型和控制器,实现了代码的解耦和重用,提高了项目的可维护性和可扩展性。详细讲解了分离视图、分离模型和分离控制器的具体步骤和规则,以及它们在项目中的应用。同时,还介绍了基础模型的封装和控制器的命名规则。该文章适合对MVC设计模式感兴趣的读者阅读和学习。 ... [详细]
  • 从零基础到精通的前台学习路线
    随着互联网的发展,前台开发工程师成为市场上非常抢手的人才。本文介绍了从零基础到精通前台开发的学习路线,包括学习HTML、CSS、JavaScript等基础知识和常用工具的使用。通过循序渐进的学习,可以掌握前台开发的基本技能,并有能力找到一份月薪8000以上的工作。 ... [详细]
  • SpringMVC工作流程概述
    SpringMVC工作流程概述 ... [详细]
  • 2019独角兽企业重金招聘Python工程师标准
    本文介绍了2019独角兽企业对Python工程师的招聘标准,包括在AndroidManifest中定义meta-data的方法和获取meta-data值的代码。同时提供了获取meta-data值的具体实现方法。转载文章链接:https://my.oschina.net/u/244918/blog/685127 ... [详细]
  • Django + Ansible 主机管理(有源码)
    本文给大家介绍如何利用DjangoAnsible进行Web项目管理。Django介绍一个可以使Web开发工作愉快并且高效的Web开发框架,能够以最小的代价构建和维护高 ... [详细]
  • [转载]从零开始学习OpenGL ES之四 – 光效
    继续我们的iPhoneOpenGLES之旅,我们将讨论光效。目前,我们没有加入任何光效。幸运的是,OpenGL在没有设置光效的情况下仍然可 ... [详细]
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社区 版权所有