Monday, January 25, 2016

RDLC report error on MVC/Webform hybrid website: The Value expression for the query parameter contains an error : Request for the permission of type System.Security.Permissions.SecurityPermission failed.

When creating RDLC report on MVC/Webform hybrid website, the following error can occur.

The Value expression for the query parameter contains an error : Request for the permission of type System.Security.Permissions.SecurityPermission failed.

Quick workaround to address this issue is by setting up permission on local report like below.

// Default.aspx.cs
...
using System.Security;
using System.Security.Permissions;

namespace MyProj.Web.Reports
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if(!Page.IsPostBack)
    {
      ...
      ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RDLC/Report1.rdlc");
      ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(
        new PermissionSet(PermissionState.Unrestricted));
      ReportViewer1.LocalReport.Refresh();
    }
  }
}

No comments: