用 C# 和 ASP.NET MVC 编写的网站正在使用 Visual Basic 编译 ASCX 页面
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的生产应用程序的应用程序配置中是否包含以下内容?
另外,您是否已验证您的母版页/视图是否包含
语言
规范?
Does your production app have the following stuff in it's app config?
Also, have you verified that your Master Page / Views contain
and
The Language specification?
我发现需要在web.config文件中指定默认编译语言。
由于某种原因,这在我的项目(由 Visual Studio 模板构建)中没有指定。看来,在本地运行时,ASP 系统会正确推断默认语言,但在远程服务器上运行时,它默认为 Visual Basic。
默认编译语言设置如下:
其中编译标签位于配置标签中的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:
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.
事实上,我昨天遇到了这个问题......
在您的 .ascx 文件中,您需要在页面顶部包含具有适当语言属性的控制指令:
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: