I'm facing following problem. I've got Service Stack-based webservice which I want have on shared hosting. When deploying there and trying to open an url I'm getting following 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 for the
permission of type 'System.Security.Permissions.ReflectionPermission,
mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type
'System.Security.Permissions.ReflectionPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.] System.Security.CodeAccessSecurityEngine.Check(Object
demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, StackCrawlMark& stackMark) +34
System.Security.CodeAccessPermission.Demand() +46
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Module m,
StackCrawlMark& stackMark, Boolean skipVisibility) +243
System.Reflection.Emit.DynamicMethod..ctor(String name, Type
returnType, Type[] parameterTypes, Module m, Boolean skipVisibility)
+48 ServiceStack.Text.ReflectionExtensions.GetConstructorMethodToCache(Type
type) +586
ServiceStack.Text.ReflectionExtensions.GetConstructorMethod(Type type)
+68 ServiceStack.Text.ReflectionExtensions.CreateInstance(Type type) +8
ServiceStack.ServiceHost.ServiceController.RegisterNServiceExecutor(Type
requestType, Type serviceType, ITypeFactory serviceFactoryFn) +123
ServiceStack.ServiceHost.ServiceController.RegisterNService(ITypeFactory
serviceFactoryFn, Type serviceType) +287
ServiceStack.ServiceHost.ServiceController.Register(ITypeFactory
serviceFactoryFn) +96
ServiceStack.ServiceHost.ServiceManager.Init() +50
ServiceStack.WebHost.Endpoints.AppHostBase.Init() +43
DarkMindFx.Global.Application_Start(Object sender, EventArgs e) +571
So it seems like ServiceStack cannot perform the reflaction.
I've also tried to
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
to web.config but as the result hosting returns me an error with this line in web.config.
Does anyone ever faced such issue? Any ideas how to solve it?
The SecurityException is because GoDaddy doesn't support full trust ASP.NET hosting. You can try requesting their support to enable it for your site, otherwise you would need to use a different hosting provider.
Related
For my current project I use Dapper. Everything perfect. Then I needed to deploy it on shared hosting. The result can be seen here (copied YSOD):
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 for the
permission of type 'System.Security.Permissions.ReflectionPermission,
mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
Stack trace
[SecurityException: Request for the permission of type
'System.Security.Permissions.ReflectionPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.] System.Security.CodeAccessSecurityEngine.Check(Object
demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, StackCrawlMark& stackMark) +31
System.Security.CodeAccessPermission.Demand() +46
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner,
StackCrawlMark& stackMark, Boolean skipVisibility) +9461551
System.Reflection.Emit.DynamicMethod..ctor(String name, Type
returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility)
+40 Dapperx.SqlMapper.CreateParamInfoGenerator(Identity identity) +537 Dapperx.SqlMapper.GetCacheInfo(Identity identity) +376 Dapperx.d__131.MoveNext() +644
System.Collections.Generic.List1..ctor(IEnumerable1 collection) +327
System.Linq.Enumerable.ToList(IEnumerable1 source) +58
Dapperx.SqlMapper.Query(IDbConnection cnn, String sql, Object param,
IDbTransaction transaction, Boolean buffered, Nullable1
commandTimeout, Nullable1 commandType) +199
...
Is there any way how to solve it for (in .NET 4.0)?
As far as I understand what I've read so far, the provider has to allow some parts from reflection for the IIS which might be a security risk for them...
Reflection.Emit which is used by Dapper is not allowed in Medium Trust.
You should find a hosting provider that offers Full Trust. discountasp.net is one I have used before.
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 for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0
System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) +42
System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies, String typeName, Boolean ignoreCase) +145
System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError) +73
System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) +111
System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData) +279
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
You should change the application trust level in your web.config
Add something like this to your system.web section:
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
</system.web>
If it works, decrease your trustLevel to High, then to Medium, then to Low to see which trust level is sufficient for your application.
Actually I found the Issue, the project was created in an network not on my local. Thanks for your time to have look into this
Whe I try to run my site locally I get this error:
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 for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Stacktrace:
[SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0
System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies, String typeName, Boolean ignoreCase) +201
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +302
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +64
I'm not running across a UNC share or accessing any shared network resources. It's a .NET 3.5 site running on IIS7 on a windows 7 box.
I don't think I made any changes before this started happening, and since it has I've rebuilt the solution & restarted the computer.
Try the following. It has to do with Application Pool setting, "Load User Profile=True".
I have a web application in .Net in which I use Ajax controls in some pages. Those pages are working in localhost, but when hosted, the pages in which Ajax included shows following error.
Server Error in '/Allforkids' Application.
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 for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +58
System.Reflection.Assembly.VerifyCodeBaseDiscovery(String codeBase) +118
System.Reflection.Assembly.get_CodeBase() +35
System.Web.Handlers.ScriptResourceHandler.GetCodeBaseWithAssert(Assembly assembly) +31
System.Web.Handlers.ScriptResourceHandler.GetLastWriteTime(Assembly assembly) +36
System.Web.Handlers.ScriptResourceHandler.GetAssemblyInfoInternal(Assembly assembly) +61
System.Web.Handlers.ScriptResourceHandler.GetAssemblyInfo(Assembly assembly) +62
System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +325
System.Web.Handlers.ScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +33
System.Web.UI.ScriptManager.GetScriptResourceUrl(String resourceName, Assembly assembly) +89
System.Web.UI.ScriptRegistrationManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +111
System.Web.UI.ScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +9
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
Can anybody give appropriate solution to get rid of this error?
This looks like something you need to bring up with your hosting provider. It would appear from the error that a configuration setting in the hosting server prohibits access to local files.
You could try adding this to your web.config:
<system.web>
...
<trust level="Medium" originUrl="" />
...
</system.web>
But, if the hosting provider has a setting in the machine.config that supersedes this, it will not make a difference. Here more information on that.
It could be security permissions on your folder/files. Are you writing to any files (like an Access DB)? Make sure your ASP.Net machine account (such as PCName\ASPNET) on the server has access to the folder.
Here is the code from the Assembly class:
private void VerifyCodeBaseDiscovery(String codeBase)
{
if ((codeBase != null) &&
(String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) == 0)) {
System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase );
new FileIOPermission( FileIOPermissionAccess.PathDiscovery, urlString.GetFileName() ).Demand();
}
}
The exception is thrown on the .Demand() method asking for FileIOPermissionAccess.PathDiscovery to the file containing the script.
My guess is the IIS worker process does not have READ/BROWSE access to the path containing the script.
If you are registering your own scripts to the ScriptManager, check the filepath (usual rule of thumb, the scripts should not be in a parent (eg. ..\Scripts) folder).
If this exception trows on the AJAX Extensions script resources there might be a problem with the installation of the AJAX Extensions.You need to ask your hosting provider to check it.
PS. Is there more to the stack trace? It seems odd that the first call in the stack is "RegisterClientScriptResource".
Setting up a new developing workstation, when I run the ASP.NET (MVC) application from Visual Studio 2008 I get a SecurityException. Any ideas what might be the problem?
I am accessing the data files over SMB (it's a shared mounted as Z:) and I've given full trust to it by running
caspol -m -ag 1 -url "\\server\share\" FullTrust -exclusive on
The full traceback is:
Server Error in '/' Application.
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 for the permission of type 'System.Web.AspNetHostingPermission,
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type
'System.Web.AspNetHostingPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean
ignoreCase) +0
System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean
ignoreCase) +42
System.Web.UI.Util.GetTypeFromAssemblies(ICollection
assemblies, String typeName, Boolean ignoreCase) +145
System.Web.UI.TemplateParser.GetType(String
typeName, Boolean ignoreCase, Boolean throwOnError) +73
System.Web.UI.TemplateParser.ProcessInheritsAttribute(String
baseTypeName, String codeFileBaseTypeName, String src,
Assembly assembly) +111
System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary
parseData) +279
Version Information: Microsoft .NET
Framework Version:2.0.50727.4927;
ASP.NET Version:2.0.50727.4927
Are you using a virtual directory that points to a remote share?
http://support.microsoft.com/?id=320268
Also take a look at "Troubleshooting common permissions and security-related issues in ASP.NET"
http://support.microsoft.com/?id=910449
Here's a command which worked for me:
C:\Windows\System32>C:\Windows\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "http://localhost/*" FullTrust