The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

swake (6) [Avatar] Offline
#1
Teo,

I have been trying to get some of your sample code running from the DevX article (http://www.devx.com/dotnet/Article/30610/0/page/5) and keep getting a strange error message when I try to run the report.

Here is the code from the Report Properties/Code tab:
Public Function GetAppPath() As String
return String.Format("http://{0}{1}/", System.Web.HttpContext.Current.Server.MachineName, System.Web.HttpContext.Current.Request.ApplicationPath)
End Function

I have added a reference to System.Web v2.0.0.0 on the References tab.

And here is the code that calls this function, which is in the Jump to URL option of the Action property of a text box:
=Code.GetAppPath() & "ReportViewer.aspx?ExpandAllToggle=True"

The error message that I receive when I preview the report:
[rsRuntimeErrorInExpression] The Hyperlink expression for the textbox ‘txtExpandAll.ActionInfo.Action’ contains an error: Object reference not set to an instance of an object.

This makes the hyperlink not work at all, even when deployed to the server and viewed in Report Manager the link does not work at all.

I notice in this article you talk about adding the AddTrustedCodeModuleInCurrentAppDomain on the ReportViewer for local mode, but I am trying to run my reports in Remote mode, which does not appear to have any of these properties available.

What else do I need to do to get this code working for reports that render in Remote mode?

Thanks,

Steve
tlachev (687) [Avatar] Offline
#2
Re: GetAppPath() - Remote Mode Problem
I can't tell from the top of my head why it is not working in Remote Mode. HttpContext is null in design mode so design mode (Report Designer) won't work but a deployed report should work.

You may want to move this code to an external class library and debug it by attaching to the Report Server process.
swake (6) [Avatar] Offline
#3
Re: GetAppPath() - Remote Mode Problem
I have now moved this function to an external dll that I have verified runs fine in any other web application that I add the reference for it. But, when I try to execute it in any of my reports I get the following error message:
Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (rsRuntimeErrorInExpression)
with #Error being displayed in the textbox that I have put the reference to the assembly in.

I have added the new assembly on the References tab of the Report Properties and added the following into the rssrvpolicy.config and rsmgrpolicy.config:
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="FRSSSRS"
Description="This group grants full permission for the FRSSSRS Custom Assembly">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1.0.0.0"
PublicKeyBlob="8caf38cdb28a22e0"/>
</CodeGroup>

Here is how I am referencing the call to the assembly in the report, now in the Value property of a textbox:
=FRSSSRS.SSRSMethods.GetAppPath()

And just to go ahead and list everything, here is the current version of the source for this assembly:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Permissions;

namespace FRSSSRS
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Unrestricted)]
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]
public class SSRSMethods
{
public static string GetAppPath()
{
string path = string.Format("http://{0}{1}/", System.Web.HttpContext.Current.Server.MachineName, System.Web.HttpContext.Current.Request.ApplicationPath);
return path;
}
}
}

The dll for this assembly has been copied the appropriate SSRS and VS folders as well.

That should cover everything that I have tried all day today, with no success. Any help would be much appreciated.

Steve

Message was edited by:
swake
tlachev (687) [Avatar] Offline
#4
Re: GetAppPath() - Remote Mode Problem
The CodeGroup has to be URL-based and must specify the full path to the binary. I don't have access to the policy file I used for the sample but the book has examples of URL-based policies.
swake (6) [Avatar] Offline
#5
Re: GetAppPath() - Remote Mode Problem
> The CodeGroup has to be URL-based and must specify
> the full path to the binary. I don't have access to
> the policy file I used for the sample but the book
> has examples of URL-based policies.

Thanks for helping with this Teo. Is there a specific place in these policy files that I should be inserting this CodeGroup? I changed it to URL, so it now looks like this:
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="FRSSSRS"
Description="This group grants full permission for the FRSSSRS Custom Assembly">
<IMembershipCondition >
class="UrlMembershipCondition"
version="1.0.0.0"
Url="Csmilierogram FilesMicrosoft SQL ServerMSSQL.3Reporting ServicesReportServerinFRSSSRS.dll"/>
</CodeGroup>

But I am still receiving the same error message about the ASPNetHostingPermission. I can't seem to figure out what is going on with such a simple external assembly call that would be causing this much trouble.

Thanks again,

Steve
tlachev (687) [Avatar] Offline
#6
Re: GetAppPath() - Remote Mode Problem
The end should look like this (not the tripple CodeGroup end element)

<CodeGroup class="UnionCodeGroup" version="1" Name="SecurityExtensionCodeGroup" Description="Code group for the AdventureWorks Utils library" PermissionSetName="FullTrust">
<IMembershipCondition class="UrlMembershipCondition" version="1" >
Url="your url to the file"
/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>
swake (6) [Avatar] Offline
#7
Re: GetAppPath() - Remote Mode Problem
Sorry, still appears that I am missing something. I'm still get that same error message. Here is the whole rssrvpolicy.config file:
<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition" Description="System.Security.Policy.AllMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission" Description="System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="DnsPermission" Description="System.Net.DnsPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="EnvironmentPermission" Description="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FileIOPermission" Description="System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup" Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="IsolatedStorageFilePermission" Description="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet" Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="PrintingPermission" Description="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="RegistryPermission" Description="System.Security.Permissions.RegistryPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SecurityPermission" Description="System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SocketPermission" Description="System.Net.SocketPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition" Description="System.Security.Policy.StrongNameMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup" Description="System.Security.Policy.UnionCodeGroup, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition" Description="System.Security.Policy.UrlMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPermission" Description="System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="ZoneMembershipCondition" Description="System.Security.Policy.ZoneMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet >
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all resources"/>
<PermissionSet >
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including the right to execute"/>
<PermissionSet >
class="NamedPermissionSet"
version="1"
Name="Execution">
<IPermission >
class="SecurityPermission"
version="1"
Flags="Execution"/>
</PermissionSet>
</NamedPermissionSets>
<CodeGroup >
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition >
class="AllMembershipCondition"
version="1"/>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="Execution"
Name="Report_Expressions_Default_Permissions"
Description="This code group grants default permissions for code in report expressions and Code element. ">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100512C8E872E28569E733BCB123794DAB55111A0570B3B3D4DE3794153DEA5EFB7C3FEA9F2D8236CFF320C4FD0EAD5F677880BF6C181F296C751C5F6E65B04D3834C02F792FEE0FE452915D44AFE74A0C27E0D8E4B8D04EC52A8E281E01FF47E7D694E6C7275A09AFCBFD8CC82705A06B20FD6EF61EBBA6873E29C8C0F2CAEDDA2"/>
</CodeGroup>
<CodeGroup >
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Execution"
Description="This code group grants MyComputer code Execution permission. ">
<IMembershipCondition >
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code signed with the Microsoft strong name full trust. ">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293"/>
</CodeGroup>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code signed with the ECMA strong name full trust. ">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="00000000000000000400000000000000"/>
</CodeGroup>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Report_Server_Strong_Name"
Description="This code group grants Report Server code full trust. ">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100272736AD6E5F9586BAC2D531EABC3ACC666C2F8EC879FA94F8F7B0327D2FF2ED523448F83C3D5C5DD2DFC7BC99C5286B2C125117BF5CBE242B9D41750732B2BDFFE649C6EFB8E5526D526FDD130095ECDB7BF210809C6CDAD8824FAA9AC0310AC3CBA2AA0523567B2DFA7FE250B30FACBD62D4EC99B94AC47C7D3B28F1F6E4C8"/>
</CodeGroup>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition >
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"/>
</CodeGroup>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="SharePoint_Server_Strong_Name"
Description="This code group grants SharePoint Server code full trust. ">
<IMembershipCondition >
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100AFD4A0E7724151D5DD52CB23A30DED7C0091CC01CFE94B2BCD85B3F4EEE3C4D8F6417BFF763763A996D6B2DFC1E7C29BCFB8299779DF8785CDE2C168CEEE480E570725F2468E782A9C2401302CF6DC17E119118ED2011937BAE9698357AD21E8B6DFB40475D16E87EB03C744A5D32899A0DBC596A6B2CFA1E509BE5FBD09FACF"/>
</CodeGroup>
<CodeGroup >
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="SecurityExtensionCodeGroup"
Description="This group grants full permission for the FRSSSRS Custom Assembly">
<IMembershipCondition >
class="UrlMembershipCondition"
version="1"
Url="Csmilierogram FilesMicrosoft SQL ServerMSSQL.3Reporting ServicesReportServerinFRSSSRS.dll"/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>

Steve
swake (6) [Avatar] Offline
#8
Re: GetAppPath() - Remote Mode Problem
Here is a dump of the error message from debugging:
System.Security.SecurityException was unhandled by user code
Message="Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="FRSSSRS"
GrantedSet="<PermissionSet class="System.Security.PermissionSet" >
version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
version="1"
Flags="Execution"/>
<IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100512C8E872E28569E733BCB123794DAB55111A0570B3B3D4DE3794153DEA5EFB7C3FEA9F2D8236CFF320C4FD0EAD5F677880BF6C181F296C751C5F6E65B04D3834C02F792FEE0FE452915D44AFE74A0C27E0D8E4B8D04EC52A8E281E01FF47E7D694E6C7275A09AFCBFD8CC82705A06B20FD6EF61EBBA6873E29C8C0F2CAEDDA2"
Name="expression_host_6e6649952a2a4e9982ee693ccb3970ea"
AssemblyVersion="1.0.0.0"/>
<IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
version="1"
Zone="MyComputer"/>
</PermissionSet>
"
PermissionState="<PermissionSet class="System.Security.PermissionSet" >
version="1">
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
version="1"
Level="Unrestricted"
Unrestricted="true"/>
</PermissionSet>
"
RefusedSet=""
Url=""
StackTrace:
at FRSSSRS.SSRSMethods.GetAppPath()
at ReportExprHostImpl.textbox4_TextBoxExprHost.get_ValueExpr()
at Microsoft.ReportingServices.ReportProcessing.ReportRuntime.EvaluateTextBoxValueExpression(TextBox textBox)

I can't even figure out what most of this message is trying to tell me.

Steve
swake (6) [Avatar] Offline
#9
Re: GetAppPath() - Remote Mode Problem
SUCCESS!

I finally got this working, but I'm not totally sure what combination of the 30 things that I have tried for the last 2 days finally got it to work.

I think that the real solution is in the assertions that are in my custom assembly. Before I had:
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Unrestricted)]

Once I changed it to:
[AspNetHostingPermission(SecurityAction.Assert, Level = AspNetHostingPermissionLevel.Unrestricted)]

The call now works perfectly!

Thanks Teo for all your help, I'll see you at Tech-Ed next month!

Steve
joshcsmith13 (1) [Avatar] Offline
#10
Re: GetAppPath() - Remote Mode Problem
>> I think that the real solution is in the assertions that are in my custom assembly. Before I had:
>> [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Unrestricted)]

>> Once I changed it to:
[AspNetHostingPermission(SecurityAction.Assert, Level = AspNetHostingPermissionLevel.Unrestricted)]

>> The call now works perfectly!

Bingo!! this is precisely what we just worked through.

I just wanted to affirm your "assertion" smilie and raise this thread's relevance since this was a hard egg to crack!