部署后,我通过Visual Studio通过FTP上传了asp.net应用程序,这引发了运行时错误(解析错误)。
我看过几篇文章,并尝试了许多替代方法,但都没有用:
上传后,错误是:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details
and modify your source file appropriately.
Parser Error Message: Could not load type 'SimpleEchoBot.WebApiApplication'.
Source Error:
Line 1: <%@ Application CodeBehind="Global.asax.cs"
Inherits="SimpleEchoBot.WebApiApplication" Language="C#" %>
Source File: /global.asax Line: 1
如这篇文章中所述:Parser Error Message: Could not load type 'webmarketing',我将CodeBehind更改为CodeFile,但是出现了一个新错误,指出asax.cs不存在!
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: The file '/Global.asax.cs' does not exist.
Source Error:
Line 1: <%@ Application CodeFile="Global.asax.cs"
Inherits="SimpleEchoBot.WebApiApplication" Language="C#" %>
Source File: /global.asax Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET
Version:4.7.3282.0
当时我的plesk文件管理器如下所示:
然后我上传Global.asax.cs文件,然后出现此错误:
如这篇文章中所示:Parser Error: Server Error in '/' Application我更改了Global.asax.cs命名空间,使其等于asax中的继承路径!
asax.cs中的已修改名称空间代码:
asax中的代码:
<%@ Application CodeBehind="Global.asax.cs" Inherits="SimpleEchoBot.WebApiApplication" Language="C#" %>
但是,仍然出现上述“该程序被组策略阻止”错误!
然后我将相同的应用程序部署到Azure,出现了相同的解析错误,上面出现了!
“ /”应用程序中的服务器错误。 解析器错误 说明:在解析服务于此请求所需的资源期间发生错误。请查看以下特定的解析错误详细信息,并适当地修改您的源文件。
Parser Error Message: Could not load type 'SimpleEchoBot.WebApiApplication'.
源错误:
第1行:<%@ Application CodeBehind =“ Global.asax.cs”> Inherits =“ SimpleEchoBot.WebApiApplication” Language =“ C#”%>
源文件:/global.asax行:1
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.7.3163.0
编辑:根据jessehouwing的要求,以下是Bin文件夹的屏幕截图:
正如@jeesehouwing评论提到的那样,我尝试对网站进行预编译并上传,但是在预编译时我收到了一些错误:
System.AggregateException: One or more errors occurred. --->
System.Exception: Publish failed due to build errors. Check the error list
for more details.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,
CancellationToken cancellationToken)
at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.
<>c__DisplayClass40_0.<PublishAsync>b__2()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) atSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)atMicrosoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__88.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors.
Check the error list for more details.<---
答案 0 :(得分:0)
看起来您只能上载预编译的网站,而不能在您的部署中包含Roslyn编译器,因为它被主机阻止了。您可以在Visual Studio中使用“发布配置文件”来配置预编译(我怀疑您需要选择“不可更新”选项)。
另请参阅:
您的虚拟主机似乎已将允许运行的可执行文件列入白名单。这是使环境更安全的强化实践。最新版本的ASP.NET包括C#编译器,作为部署的一部分,可即时编译MVC视图和其他元素。为此,您的应用程序将csc.exe
编译器可执行文件与Web应用程序一起提供。提供者尚未将csc.exe
列入白名单,这阻碍了Global.asax.cs
的动态重新编译。
要么以ASP.NET的较早版本(不提供roslyn编译器框架)为目标,要么预编译网站,以使其不再依赖于roslyn编译器。