2016-02-11 41 views
3

我已經在ASP.net MVC4,框架版本4.5中開發了一個小型webapp。在使用Visual Studio 2015進行調試時,這一切都像一個魅力。但是我沒有Windows服務器,而是Linux(Ubuntu 14.04 VPS),我希望在那裏部署。mod_mono asp MVC4錯誤:System.Security.SecurityException - 無法模擬令牌

我有最新的mono和mod_mono與apache2運行。它似乎執行,因爲它應該,但我得到一些錯誤。

我解決了其中的第一個問題,加入<customError mode="off">也看到了錯誤,然後添加了一個mono/register文件夾。

但我現在這個錯誤難倒:

System.Security.SecurityException 
Couldn't impersonate token. 

Description: HTTP 500.Error processing request. 
Details: Non-web exception. Exception origin (name of application or object): mscorlib. 
Exception stack trace: 
    at System.Security.Principal.WindowsImpersonationContext..ctor (IntPtr token) <0x41ef9dd0 + 0x0006f> in <filename unknown>:0 
    at System.Security.Principal.WindowsIdentity.Impersonate (IntPtr userToken) <0x41ef9d50 + 0x0003c> in <filename unknown>:0 
    at System.CodeDom.Compiler.Executor.ExecWaitWithCapture (IntPtr userToken, System.String cmd, System.String currentDir, System.CodeDom.Compiler.TempFileCollection tempFiles, System.String& outputName, System.String& errorName) <0x41ef9c90 + 0x00038> in <filename unknown>:0 
    at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.Compile (System.CodeDom.Compiler.CompilerParameters options, System.String compilerFullPath, System.String arguments, System.String& outputFile, System.Int32& nativeReturnValue) <0x41ef9a10 + 0x0010b> in <filename unknown>:0 
    at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) <0x41ef5c40 + 0x005fb> in <filename unknown>:0 
    at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) <0x41ef5aa0 + 0x000c7> in <filename unknown>:0 
    at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) <0x41ef58f0 + 0x0004d> in <filename unknown>:0 
    at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) <0x41ee0a70 + 0x00991> in <filename unknown>:0 
    at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) <0x41ee0a30 + 0x00023> in <filename unknown>:0 
    at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, Boolean debug) <0x41ed6b10 + 0x009b7> in <filename unknown>:0 
    at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) <0x41eac440 + 0x00523> in <filename unknown>:0 
    at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) <0x41eabbc0 + 0x0011b> in <filename unknown>:0 
    at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) <0x41eaaa70 + 0x00093> in <filename unknown>:0 
    at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) <0x41eaa690 + 0x00017> in <filename unknown>:0 
    at System.Web.HttpApplicationFactory.InitType (System.Web.HttpContext context) <0x41e9c4a0 + 0x0041b> in <filename unknown>:0 

我一直無法修復該錯誤。我曾嘗試以下步驟:

  • 公佈的項目到本地文件夾並將其複製到我的Linux
  • 服務器採取了整個項目,並添加到Linux服務器建造
  • 整個項目的Linux上xbuild

這都給出了相同的運行時錯誤。

我用特拉維斯CI來檢查我的代碼,並將其傳遞,具有以下配置:

language: CSharp 
solution: BannedFromHighsec.sln 
script: 
    - nuget restore BannedFromHighsec.sln 
    - xbuild /p:Configuration=Release /target:BannedFromHighsec BannedFromHighsec.sln /p:TargetFrameworkVersion="v4.5" /p:DebugSymbols=False 

引擎收錄的特拉維斯CI日誌:http://pastebin.com/5s6p97i3

所以我還挺想朝這是我的代碼,還有的有什麼問題。但我不確定它是什麼,因爲它是一個簡單的應用程序。使用SQlite和從API和第二個數據庫提取數據的操作非常基本。我沒有使用登錄或任何東西。

我希望有人可以幫助我,我開始得到一個asp.net MVC的句柄,並且想知道如何在Linux上實際部署它,如果可能的話。 :)

如果您需要任何其他信息,配置,源代碼讓我知道,我會很樂意給它。只是不知道該錯誤代碼需要什麼。

回答

11

我會先說我的設置與您的設置不同。我有一個在Raspberry Pi 2上運行.NET 4.5.2的ASP.NET MVC網站,運行Raspbian Jessie(2016年2月版)。這個發行版本的股票單聲道是3.2.8,但我升級到4.2.2。

所以,我遇到了與我試圖讓測試站點運行時完全相同的錯誤消息。什麼對我有用,是從我的web.config註釋掉<編譯器>條目,如下所示。

<system.codedom> 
    <compilers> 
    <!-- 
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    --> 
    </compilers> 
</system.codedom> 

然後重新apache服務後

sudo service apache2 restart 

然後在這之後,MVC網站裝載了就好了。

我不能說這是一個完美的解決方案,因爲我不知道爲什麼評論這些行的XML工作。如果這對你有效,那很好,但我希望有人能向我解釋爲什麼這兩行XML是造成這個問題的原因。

+0

OMFG。我愛你!!!! 我花了很多時間在這個問題上,有點放棄了。感謝這個工程! :D 我不得不修復一些其他錯誤,但主要是由於Sqlite需要定製構建.dll。並不得不刪除「Microsoft.Ai.Web.dll」 – Frederik

+0

令人難以置信,也花了很長時間在這些錯誤,並遵循你的解決方案,現在它的工作原理! – Sierramike

+0

這些行配置給定編譯器[1]應如何處理每個擴展。所以我猜Mono編譯器無法匹配引發'SecurityException'的'type'和'publickey'屬性。問題是......哪些是單聲道編譯器的類型?儘管你應該可以將pubkey屬性留空[2]。 [1] https://msdn.microsoft.com/en-us/library/y9x69bzw(v=vs.110).aspx [2] https://msdn.microsoft.com/en-us/library/yfsftwz6( v = vs.110).aspx – Sdlion

1

註釋掉編譯器條目作爲公認的答案有效建議禁用Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet包 - 如果您計劃只在單聲道運行自己的網站,最好完全卸載它加Microsoft.Net.Compilers(前者的依賴),因爲它是沒有用的 - mono可能與它不兼容,並且它有自己的服務API編譯器。