背景:我創建了一個自定義的HttpHandler,它根據用戶發佈的參數執行特定的命令。由於JQuery Ajax在我的網站中大量使用,我採用了內容頁面方法,在該方法中,我執行一個aspx頁面,其中包含用戶正在查看的容器頁面的內容。 截至目前我正在使用Godaddy共享主機,因爲該網站還處於初級階段,所以我不能去專用/虛擬服務器。PageParser.GetCompiledPageInstance拋出一個SecurityException - 如何解決這個問題?
一切工作正常在我的電腦上,但不是在服務器上。 我得到這個錯誤:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Web.UI.PageParser.GetCompiledPageInstance(String virtualPath, String inputFile, HttpContext context) +46 SL.Controller.Commands.CommandHelper.ExecutePage(SLActionInfo actionInfo, String url) +95 SL.Controller.Commands.ProductCommand.Execute(SLActionInfo actionInfo) +32 SL.Controller.CommandFactory.ExecuteCommand(HttpContext context) +224 SL.Controller.DefaultHttpHandler.ProcessRequest(HttpContext context) +20 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 ....
奇怪的事情:使用Server.Execute(字符串virtualUrl)工作,但PageParser.GetCompiledPageInstance不是。
爲什麼我使用PageParser.GetCompiledPageInstance而不是Server.Execute(字符串url)?因爲下面的代碼:
public static string ExecutePage(SLActionInfo actionInfo, string url) { var context = actionInfo.Context; var sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); IHttpHandler handler = PageParser.GetCompiledPageInstance(url, context.Server.MapPath(url), context); if (handler is SL.UI.SLPageBase) ((SL.UI.SLPageBase)handler).ActionInfo = actionInfo; context.Server.Execute(handler, htw, true); return sw.ToString(); }
由於我的內容頁面從SLPageBase(頁的子類)推導出有一個屬性ActionInfo這需要在這ExecutePage方法進行設置,我使用PageParser方法。
我不知道如何擺脫這個錯誤,而不會破壞我的PageParser方法。
任何幫助將不勝感激。
正如MSDN所說,不要使用PageParser.GetCompiledPageInstance方法。改爲測試'BuildManager.CreateInstanceFromVirtualPath'。 – 2011-05-09 12:49:47
@Mehdi我沒有意識到,有一些名爲BuildManager.CreateInstanceFromVirtualPath。感謝它,我會嘗試一下,看它是否在部分信任下的共享主機中工作。 – 2011-05-10 04:07:47