用 C# 和 ASP.NET MVC 编写的网站正在使用 Visual Basic 编译 ASCX 页面

发布于 2024-08-30 07:39:15 字数 180 浏览 5 评论 0原文

我正在使用 C# 在 ASP.NET MVC 中开发一个网站。它在我的机器上运行良好,但是当我将其加载到生产服务器时,它会在尝试显示主页时生成错误。

该错误是由于 ASP 系统使用 Visual Basic 编译 .ascx 页而引起的,这当然是行不通的,因为所有代码都是用 C# 编写的。

我该如何解决这个问题?

I am developing a website in ASP.NET MVC using C#. It works fine on my machine, however when I load it to the production server it generates an error trying to present the home page.

The error is caused by the fact that the ASP system is compiling the .ascx pages using Visual Basic, which, of course, does not work since all of the code is in C#.

How do I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

轻许诺言 2024-09-06 07:39:15

您的生产应用程序的应用程序配置中是否包含以下内容?

<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="WarnAsError" value="false"/>
</compiler>

另外,您是否已验证您的母版页/视图是否包含

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<YourType>" %>

语言

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<LoginPageView>" %>

规范?

Does your production app have the following stuff in it's app config?

<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="WarnAsError" value="false"/>
</compiler>

Also, have you verified that your Master Page / Views contain

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<YourType>" %>

and

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<LoginPageView>" %>

The Language specification?

梦魇绽荼蘼 2024-09-06 07:39:15

我发现需要在web.config文件中指定默认编译语言。

由于某种原因,这在我的项目(由 Visual Studio 模板构建)中没有指定。看来,在本地运行时,ASP 系统会正确推断默认语言,但在远程服务器上运行时,它默认为 Visual Basic。

默认编译语言设置如下:

<compilation
   defaultLanguage="c#"
/> 

其中编译标签位于配置标签中的system.web标签中。请注意,defaultLanguages 中的 L 大写。另请注意,通常此标签中已经包含许多其他信息,您只需添加 defaultLanguage 属性即可。

I found that the default compiler language needs to be specified in the web.config file.

For some reason this is not specified in my project (which was built by a Visual Studio template). It appears that when running locally the ASP system correctly infers the default language, but when running on a remote server it defaults to Visual Basic.

The default compiler language setting is set as follows:

<compilation
   defaultLanguage="c#"
/> 

where the compilation tag is in the system.web tag which is in the configuration tag. Note that there is a capital L in defaultLanguages. Also note that normally this tag will already be present with lots of other information in it, you need to just add the defaultLanguage attribute.

Bonjour°[大白 2024-09-06 07:39:15

事实上,我昨天遇到了这个问题......

在您的 .ascx 文件中,您需要在页面顶部包含具有适当语言属性的控制指令:

<%@ Control Language="C#" ... %>

I had this problem yesterday, as a matter of fact...

In your .ascx files, you need to include the control directive with the appropriate language attribute at the top of the page:

<%@ Control Language="C#" ... %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文