I downloaded a template from a website (about a year ago) for this site and appear to be having problems with the trust level on the website. The hosting solution I have has my asp security at medium level, and I dont think I can get it changed.
When I load the site i'm getting:
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.
What I've tried:
I changed the publish options in Visual Studio 2008 to use a Strong Name Took file I created. As well I checked the, Mark assembiles with AllowPartiallyTrustedCallerAttribute.
I think that there is something in my VB file that still wants/needs full permissions and I cant quite figure out what.
The VB Script:
Imports System.CodeDom
Imports System.ComponentModel
Imports System.Web.Compilation
Imports System.Web.Configuration
Imports System.Configuration
''' <summary>
''' Class that enables the creation of expressions containing the current theme or stylesheet theme as set in
''' the <c>pages</c> section of web.config.
''' </summary>
''' <remarks>
''' <para>The following two types of expressions are supported:
''' 1. <c><%$ Themes:StylesheetTheme %></c> or
''' 2. <c><%$ Themes:StylesheetTheme(<some format string>
%></c>, where <c><some format
''' string></c> can contain one placeholder, such as '~/App_Themes/{0}/Images/someimage.gif'.</para>'''
''' <para>You can query both the <c>StyleSheetTheme</c> and <c>Theme</c> properties. The respective expressions
''' are <c><%$ Themes:StylesheetTheme %></c> and <c><%$ Themes:Theme %></c>.</para>
''' </remarks>
<System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _
<ExpressionPrefix("Themes")> _
Public Class ThemesExpressionBuilder
Inherits System.Web.Compilation.ExpressionBuilder
Private Const STYLESHEET_THEME As String = "stylesheettheme"
Private Const THEME As String = "theme"
Public Overrides Function GetCodeExpression(ByVal entry As System.Web.UI.BoundPropertyEntry, ByVal parsedData As Object, ByVal context As System.Web.Compilation.ExpressionBuilderContext) As System.CodeDom.CodeExpression
Dim expressionArray(0) As CodeExpression
expressionArray(0) = New CodePrimitiveExpression(entry.Expression.Trim())
Return New CodeMethodInvokeExpression(New CodeTypeReferenceExpression(MyBase.GetType()), "GetEvalData", expressionArray)
End Function
Public Overrides ReadOnly Property SupportsEvaluate() As Boolean
Get
Return True
End Get
End Property
Public Overrides Function EvaluateExpression(ByVal target As Object, ByVal entry As System.Web.UI.BoundPropertyEntry, ByVal parsedData As Object, ByVal context As System.Web.Compilation.ExpressionBuilderContext) As Object
Return GetEvalData(entry.Expression)
End Function
Public Shared Function GetEvalData(ByVal expression As String) As Object
Dim result As String = String.Empty
' Get the Web application configuration.
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
' Get the 'pages' section.
Dim pagSection As PagesSection = CType(config.GetSection("system.web/pages"), PagesSection)
Dim hasArgs As Boolean = System.Text.RegularExpressions.Regex.IsMatch(expression, ".+\(.+\)", RegexOptions.IgnorePatternWhitespace Or RegexOptions.Compiled Or RegexOptions.IgnoreCase)
'Determine the expression result
If expression.ToLowerInvariant().StartsWith(STYLESHEET_THEME) Then
If hasArgs Then
expression = expression.Substring(STYLESHEET_THEME.Length + 1, expression.Length - STYLESHEET_THEME.Length - 2)
Dim helper As System.Web.UI.Control = New Control()
result = helper.ResolveUrl(String.Format(expression, pagSection.StyleSheetTheme))
Else
result = pagSection.StyleSheetTheme
End If
ElseIf expression.ToLowerInvariant().StartsWith(THEME) Then
If hasArgs Then
expression = expression.Substring(THEME.Length + 1, expression.Length - THEME.Length - 2)
Dim helper As System.Web.UI.Control = New Control()
result = helper.ResolveUrl(String.Format(expression, pagSection.Theme))
Else
result = pagSection.Theme
End If
End If
Return result
End Function
End Class
When I load the site i'm getting:
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.
What I've tried:
I changed the publish options in Visual Studio 2008 to use a Strong Name Took file I created. As well I checked the, Mark assembiles with AllowPartiallyTrustedCallerAttribute.
I think that there is something in my VB file that still wants/needs full permissions and I cant quite figure out what.
The VB Script:
Imports System.CodeDom
Imports System.ComponentModel
Imports System.Web.Compilation
Imports System.Web.Configuration
Imports System.Configuration
''' <summary>
''' Class that enables the creation of expressions containing the current theme or stylesheet theme as set in
''' the <c>pages</c> section of web.config.
''' </summary>
''' <remarks>
''' <para>The following two types of expressions are supported:
''' 1. <c><%$ Themes:StylesheetTheme %></c> or
''' 2. <c><%$ Themes:StylesheetTheme(<some format string>
''' string></c> can contain one placeholder, such as '~/App_Themes/{0}/Images/someimage.gif'.</para>'''
''' <para>You can query both the <c>StyleSheetTheme</c> and <c>Theme</c> properties. The respective expressions
''' are <c><%$ Themes:StylesheetTheme %></c> and <c><%$ Themes:Theme %></c>.</para>
''' </remarks>
<System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _
<ExpressionPrefix("Themes")> _
Public Class ThemesExpressionBuilder
Inherits System.Web.Compilation.ExpressionBuilder
Private Const STYLESHEET_THEME As String = "stylesheettheme"
Private Const THEME As String = "theme"
Public Overrides Function GetCodeExpression(ByVal entry As System.Web.UI.BoundPropertyEntry, ByVal parsedData As Object, ByVal context As System.Web.Compilation.ExpressionBuilderContext) As System.CodeDom.CodeExpression
Dim expressionArray(0) As CodeExpression
expressionArray(0) = New CodePrimitiveExpression(entry.Expression.Trim())
Return New CodeMethodInvokeExpression(New CodeTypeReferenceExpression(MyBase.GetType()), "GetEvalData", expressionArray)
End Function
Public Overrides ReadOnly Property SupportsEvaluate() As Boolean
Get
Return True
End Get
End Property
Public Overrides Function EvaluateExpression(ByVal target As Object, ByVal entry As System.Web.UI.BoundPropertyEntry, ByVal parsedData As Object, ByVal context As System.Web.Compilation.ExpressionBuilderContext) As Object
Return GetEvalData(entry.Expression)
End Function
Public Shared Function GetEvalData(ByVal expression As String) As Object
Dim result As String = String.Empty
' Get the Web application configuration.
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
' Get the 'pages' section.
Dim pagSection As PagesSection = CType(config.GetSection("system.web/pages"), PagesSection)
Dim hasArgs As Boolean = System.Text.RegularExpressions.Regex.IsMatch(expression, ".+\(.+\)", RegexOptions.IgnorePatternWhitespace Or RegexOptions.Compiled Or RegexOptions.IgnoreCase)
'Determine the expression result
If expression.ToLowerInvariant().StartsWith(STYLESHEET_THEME) Then
If hasArgs Then
expression = expression.Substring(STYLESHEET_THEME.Length + 1, expression.Length - STYLESHEET_THEME.Length - 2)
Dim helper As System.Web.UI.Control = New Control()
result = helper.ResolveUrl(String.Format(expression, pagSection.StyleSheetTheme))
Else
result = pagSection.StyleSheetTheme
End If
ElseIf expression.ToLowerInvariant().StartsWith(THEME) Then
If hasArgs Then
expression = expression.Substring(THEME.Length + 1, expression.Length - THEME.Length - 2)
Dim helper As System.Web.UI.Control = New Control()
result = helper.ResolveUrl(String.Format(expression, pagSection.Theme))
Else
result = pagSection.Theme
End If
End If
Return result
End Function
End Class