Website written in C# and ASP.NET MVC is compiling ASCX pages with Visual Basic
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 si开发者_运维知识库nce all of the code is in C#.
How do I fix this?
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?
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.
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#" ... %>
精彩评论