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


推荐阅读
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • 在springmvc框架中,前台ajax调用方法,对图片批量下载,如何弹出提示保存位置选框?Controller方法 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • 导出功能protectedvoidbtnExport(objectsender,EventArgse){用来打开下载窗口stringfileName中 ... [详细]
  • HTML5网页模板怎么加百度统计?
    本文介绍了如何在HTML5网页模板中加入百度统计,并对模板文件、css样式表、js插件库等内容进行了说明。同时还解答了关于HTML5网页模板的使用方法、表单提交、域名和空间的问题,并介绍了如何使用Visual Studio 2010创建HTML5模板。此外,还提到了使用Jquery编写美好的HTML5前端框架模板的方法,以及制作企业HTML5网站模板和支持HTML5的CMS。 ... [详细]
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社区 版权所有