Security Exception Error from Premade Template

Joined
Aug 29, 2010
Messages
2
Reaction score
0
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>&lt;%$ Themes:StylesheetTheme %&gt;</c> or
''' 2. <c>&lt;%$ Themes:StylesheetTheme(&lt;some format string&gt;) %&gt;</c>, where <c>&lt;some format
''' string&gt;</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>&lt;%$ Themes:StylesheetTheme %&gt;</c> and <c>&lt;%$ Themes:Theme %&gt;</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
 
Joined
Aug 29, 2010
Messages
2
Reaction score
0
According to an article I found, the problem is:
' 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)


This isn't allowed in a Medium Trust enviroment. Which is what my hosting service uses.

I tried changing it to:
Dim config As Configuration
config = ConfigurationManager.OpenExeConfiguration("/app.config")


And creating an app.config, but its still throwing the same error.

Any help is greatly appreciated. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top