Reputation: 4431
I have created a web application in ASP.Net 4.0 framework and use LinqtoSQL for database interaction. I have build my code and upload on my shared web hosting server. Its home page working fine and all pages working fine where page content doesn't interact with database. But which pages interact database these pages gives me error :
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
How to resolve this error on our shared server??
All code works fine on our local IIS server and our testing dedicated server but our client purchased a shared server and wants to run at shared server.
Upvotes: 1
Views: 6280
Reputation: 20617
NOTE: In a shared hosting environment these setting are probably locked down, you will have to contact your host.
To use LINQ in a Web application that is running under medium trust, you must include two elements in the policy file that is defined for Medium trust. By default, the web_mediumtrust.config file is the policy file for medium trust, and these elements are installed in the file.
Within the SecurityClasses element, LINQ requires a SecurityClass element with the following attributes:
<SecurityClass
Name="ReflectionPermission"
Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Within the PermissionSet element that has the Name attribute set to "ASP.Net", LINQ requires an IPermission element that has the following attributes:
<IPermission
class="ReflectionPermission"
version="1"
Flags="RestrictedMemberAccess"
/>
Upvotes: 1