楔子:最近要上一個.net 的網站,而這個網站是採用 xslt 的,xslt 中有使用到自定義指令碼 msxsl:script,但放到 godaddy 的伺服器上去之後,卻報出了黃頁錯誤,錯誤如下:
|
Request failed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Request failed.
|
經過多方的排查,發現是由於 xslt 檔案中包含有 msxsl:script 指令碼的原因造成的,進一步細究,發現執行 msxsl:script 需要程式碼執行許可權為 full trust,而在 godaddy 的虛擬主機中,程式碼執行許可權為 Medium 。
鬱悶啊,我不太可能因為這樣而放棄在 xslt 中執行 script,因為如果不能執行 script,那麼 xslt 的開發難度將大增加,所以只好選擇其它主機了。最讓人鬱悶的是,我剛剛在 godaddy 續費,早知如此,就不去他們家續費了。
隨後,我又發信去 godaddy 和 lunarPages 諮詢關於 full trust level 的事情,得到的答覆是 godaddy 不支援,而 lp 是可以支援 full trust 的,godaddy 的主機是.net 1.1 支援 full trust level,而 lp 的主機則是完全支援的,那然後我也是花了一天的時間,去找關於 full trust 的主機,需要這個功能的朋友注意了。
哪些美國主機可以支援 Full Trust Level?
ixWebHosting 其實之前我也試過他們的主機,但是說句實在話,速度和穩定性方面實在是不也恭維,我當時是衝著 15 個 IP 去的,價格上要比 godaddy 略高,但加上送的 15 個 IP 以及 3 個免費域名,價格肯定要優於 godaddy 了,單單是 15 個獨立 IP,就值 $2*15*12=360 美元了。但從我試用並監測二十來天的情況下來看,我個人認為 ix 的 windows 主機,基本上可以不考慮。
LunarPages 我沒有用過,沒有發言權了,但 idcspy 的版主說最近速度有些慢,也不推薦購買
arvixe.com 這個公司好像在網上沒什麼訊息,中文有幾篇文章都是說好的,不排除是託,也極有可能是中國人在國外搞的小主機公司,但有一點,他們是支援 Full Trust Level 的,有用過這個公司主機的朋友留下言。
WebHost4life 這個公司比較有意思,他們有中文的客戶混在 idcspy 論壇裡,使用的人好像也不多,但可以肯定的是,支援 full trust level 的。
最後一招,自己買 VPS/VDS 或者獨立主機了,目前 godaddy 的 vds 一年大概要兩千多吧,windows 主機最起碼也得買 512 記憶體的了,太小了根本跑不起來,誰讓 windows 系列產品都是吃記憶體大戶呢。其它的也有便宜的,但我覺得應該要在 2500-3000 這個級別才可以用。
此外為了伺服器安全,很多國外的 Asp.net 虛擬主機 (比如 GoDaddy) 都把設定程式碼執行許可權設定為 Medium Trust Level,這時候,與 Full Trust Level 不同,Asp.net 程式會有很多限制。如果你正在開發通用的 Web 產品,比如 BBS 、 Blog 、 CMS 、 Portal,那麼為了讓產品能更大程度適應各種執行環境,你需要考慮到 Asp.net 中等安全模式的相關問題。
什麼是中等安全模式?
Asp.net 透過信任級別 (Trust Level) 設定程式碼執行許可權,預設有 5 種,分別是:Full 、 High 、 Medium 、 Low 、 Minimal 。虛擬主機提供商通常在系統的 machine.config 配置了<system.web><trust level=』Medium』 />…
常見異常資訊:
|
Required permissions cannot be acquired. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. SecurityException: Request for the permission of type 『System.Security.Permissions.ReflectionPermission failed 或者: System.Security.SecurityException: Request for the permission of type 『System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.
|
中等安全模式有哪些限制?
CodeDom 、 Emit 以及基於 CodeDom 、 Emit 實現的 Ioc 、 AOP 技術無法使用。
VirtualPathProvider 無法使用。
BuildProvider 無法使用。
HttpWorkRequst 無法使用。
OleDb 無法使用。預設情況下 Access 資料庫無法使用,不過 GoDaddy 可以透過管理面板將 Access 訪問許可權開啟。
P/Invoke 無法使用。 System.Data.SQLite 及 sqlite-net 都 是透過 P/Invoke 呼叫 C 語言版本的 SQLite.dll 實現的,因此也不能使用了。
ReflectionPermission 及 RestrictedMemberAccess 無法訪問,導致 Ado.net for Entity Framework 、 DB4O,以及好多 ORM 工具無法使用。
一些常見問題的解決辦法
SQLite 無法使用:可以使用 Access 或 VistaDB 作為替換。
BlogEngine.net 預設安裝時出錯:只需將 Web.config 中的<system.web><trust level=』Medium』/> 刪除即可。
LINQ to Entities / ADO.NET Entity Framework 無法使用:參考 http://mosesofegypt.net/post/Entity-Framework-minimum-permission-considerations.aspx
Discuz!net 無法使用:使用 YetAnotherForum 代替。