2011-11-23 21 views
1

我在ASP.Net 4.0框架中創建了一個Web應用程序,並使用LinqtoSQL進行數據庫交互。我已經構建了我的代碼並上傳到了我的共享虛擬主機服務器上。它的主頁工作正常,所有頁面都能正常工作,頁面內容不會與數據庫交互。但其頁面交互的數據庫這些頁面給我的錯誤:「應用程序試圖執行安全策略不允許的操作」共享虛擬主機服務器

Security Exception 

    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

    Exception Details: System.Security.SecurityException: Request failed. 
    Stack Trace: 

    [SecurityException: Request failed.] 
    DataContextFactory.GetWebRequestScopedDataContextInternal(Type type, String key, String connectionString) in DataContextFactory.cs:81 
    DataContextFactory.GetWebRequestScopedDataContext() in DataContextFactory.cs:42 
    members_buyer_mypostedjobs..ctor() in mypostedjobs.aspx.cs:19 
    ASP.members_buyer_mypostedjobs_aspx..ctor() in App_Web_soaq30qq.4.cs:0 
    __ASP.FastObjectFactory_app_web_soaq30qq.Create_ASP_members_buyer_mypostedjobs_aspx() in App_Web_soaq30qq.9.cs:0 
    System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32 
    System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109 
    System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31 
    System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37 
    System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +334 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

如何解決這個錯誤我們共享的服務器上?

所有代碼在我們的本地IIS服務器和我們的測試專用服務器上都正常工作,但我們的客戶購買了共享服務器並希望在共享服務器上運行。

+0

什麼是堆棧跟蹤? – SLaks

+1

請把它放在你的問題。 – SLaks

回答

1

注意:在共享主機環境中,這些設置可能被鎖定,您將不得不聯繫您的主機。

Using LINQ with ASP.NET

要被下中等信任運行的Web應用程序中使用LINQ,你必須包括在政策文件中的兩個元素是爲中等信任定義。默認情況下,web_mediumtrust.config文件是中等信任的策略文件,並且這些元素安裝在文件中。

內SecurityClasses元素,LINQ需要具有以下屬性SecurityClass元素:

<SecurityClass 
    Name="ReflectionPermission" 
    Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 

在其名稱屬性設置爲「ASP.Net」的PermissionSet中元素,LINQ需要有一個IPermission元素以下屬性:

<IPermission 
    class="ReflectionPermission" 
    version="1" 
    Flags="RestrictedMemberAccess" 
/> 
+0

我在哪裏可以找到「web_mediumtrust.config文件」? –

+0

@GauravAgrawal:你需要問你的主人這樣做。如果他們拒絕,切換到更好的主機。 – SLaks

+0

@SLaks謝謝我會聯繫我的託管服務提供商... –

相關問題