473,322 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Does GridView.DataBind work under medium trust with custom objects

I am having problems getting a gridview to bind to custom objects under any
non-full trust level.

I created a test project to verify what I am seeing isn't a side effect of
other code in my project and I get the same errors there:

Exception Details: System.Security.SecurityException: That assembly does not
allow partially trusted callers.

[SecurityException: That assembly does not allow partially trusted callers.]
__ASP.FastObjectFactory_app_web_hkdmcy7e.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
+643

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute() +279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444

Here is the code I have for the one page test site (using Asp.Net web
application projects).

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestWebApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="testGrid"></asp:GridView>
</div>
</form>
</body>
</html>

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
public partial class _Default : System.Web.UI.Page
{
public class MyClass
{
public MyClass()
{
name = Guid.NewGuid().ToString();
}
private string name;

public string Name
{
get { return name; }
set { name = value; }
}

}

public void Page_Load(object sender, EventArgs e)
{
testGrid.DataSource = new MyClass();
testGrid.DataBind();
}

protected void Page_PreRender(object sender, EventArgs e)
{
}
}
}

I have tried adding AllowPartiallyTrustedCallers to the assemblyinfo.cs file
for the web application, no luck.
Aug 22 '06 #1
3 1995
GridView has nothing to do with this exception. Its .Net framework that is
preventing the access.

Do you have any third party assembly involved in this dataccess process? If
so, then you need to make sure that it has correct attribute set for
Partially trusted callers. Or this assembly needs to be registered in GAC.
"Mark Leistner" <Mark Le******@discussions.microsoft.comwrote in message
news:5C**********************************@microsof t.com...
>I am having problems getting a gridview to bind to custom objects under any
non-full trust level.

I created a test project to verify what I am seeing isn't a side effect of
other code in my project and I get the same errors there:

Exception Details: System.Security.SecurityException: That assembly does
not
allow partially trusted callers.

[SecurityException: That assembly does not allow partially trusted
callers.]
__ASP.FastObjectFactory_app_web_hkdmcy7e.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig)
+643

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444

Here is the code I have for the one page test site (using Asp.Net web
application projects).

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestWebApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="testGrid"></asp:GridView>
</div>
</form>
</body>
</html>

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
public partial class _Default : System.Web.UI.Page
{
public class MyClass
{
public MyClass()
{
name = Guid.NewGuid().ToString();
}
private string name;

public string Name
{
get { return name; }
set { name = value; }
}

}

public void Page_Load(object sender, EventArgs e)
{
testGrid.DataSource = new MyClass();
testGrid.DataBind();
}

protected void Page_PreRender(object sender, EventArgs e)
{
}
}
}

I have tried adding AllowPartiallyTrustedCallers to the assemblyinfo.cs
file
for the web application, no luck.

Aug 22 '06 #2
I created another project, called TestDll and I have moved the class
definition to that file. This dll is compiled, signed and placed in the GAC.

Referencing this dll in the web application project and attempting to bind
to it causes the security error about the assembly not allowing partially
trusted callers. The dll test project does have that attribute set, as does
the web application project. The page_load event succeeds, but the
processing dies before the page_prerender event.

Also visual studio does not catch the exception, it just automatically spits
out the error:

[SecurityException: That assembly does not allow partially trusted callers.]
__ASP.FastObjectFactory_app_web_h72yepmo.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
+643

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute() +279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444

Any ideas on what I can do to debug this further?

"Winista" wrote:
GridView has nothing to do with this exception. Its .Net framework that is
preventing the access.

Do you have any third party assembly involved in this dataccess process? If
so, then you need to make sure that it has correct attribute set for
Partially trusted callers. Or this assembly needs to be registered in GAC.
"Mark Leistner" <Mark Le******@discussions.microsoft.comwrote in message
news:5C**********************************@microsof t.com...
I am having problems getting a gridview to bind to custom objects under any
non-full trust level.

I created a test project to verify what I am seeing isn't a side effect of
other code in my project and I get the same errors there:

Exception Details: System.Security.SecurityException: That assembly does
not
allow partially trusted callers.

[SecurityException: That assembly does not allow partially trusted
callers.]
__ASP.FastObjectFactory_app_web_hkdmcy7e.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig)
+643

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444

Here is the code I have for the one page test site (using Asp.Net web
application projects).

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestWebApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="testGrid"></asp:GridView>
</div>
</form>
</body>
</html>

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
public partial class _Default : System.Web.UI.Page
{
public class MyClass
{
public MyClass()
{
name = Guid.NewGuid().ToString();
}
private string name;

public string Name
{
get { return name; }
set { name = value; }
}

}

public void Page_Load(object sender, EventArgs e)
{
testGrid.DataSource = new MyClass();
testGrid.DataBind();
}

protected void Page_PreRender(object sender, EventArgs e)
{
}
}
}

I have tried adding AllowPartiallyTrustedCallers to the assemblyinfo.cs
file
for the web application, no luck.


Aug 22 '06 #3
Well,

I got my test project working after I discovered the built in http server
was not reloading my changes automatically and I had to shut it down manually
for some reason.

In my real project I still couldn't get it working, but then I saw I was
making a call to the Microsoft AntiXSSLibrary.HtmlEncode method... which
apparently does not allow non-trusted callers.

I removed those calls (change to Server.HtmlEncode) and it appears to work.
So now I am going to try and add a wrapper dll in the gac to still allow me
to use the AntiXSSLibrary. Very interesting, I wish it would have gave a
little more information about why it was failing.

"Mark Leistner" wrote:
I created another project, called TestDll and I have moved the class
definition to that file. This dll is compiled, signed and placed in the GAC.

Referencing this dll in the web application project and attempting to bind
to it causes the security error about the assembly not allowing partially
trusted callers. The dll test project does have that attribute set, as does
the web application project. The page_load event succeeds, but the
processing dies before the page_prerender event.

Also visual studio does not catch the exception, it just automatically spits
out the error:

[SecurityException: That assembly does not allow partially trusted callers.]
__ASP.FastObjectFactory_app_web_h72yepmo.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
+643

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute() +279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444

Any ideas on what I can do to debug this further?

"Winista" wrote:
GridView has nothing to do with this exception. Its .Net framework that is
preventing the access.

Do you have any third party assembly involved in this dataccess process? If
so, then you need to make sure that it has correct attribute set for
Partially trusted callers. Or this assembly needs to be registered in GAC.
"Mark Leistner" <Mark Le******@discussions.microsoft.comwrote in message
news:5C**********************************@microsof t.com...
>I am having problems getting a gridview to bind to custom objects under any
non-full trust level.
>
I created a test project to verify what I am seeing isn't a side effect of
other code in my project and I get the same errors there:
>
Exception Details: System.Security.SecurityException: That assembly does
not
allow partially trusted callers.
>
[SecurityException: That assembly does not allow partially trusted
callers.]
__ASP.FastObjectFactory_app_web_hkdmcy7e.Create_AS P_default_aspx() +0
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +194
>
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +493
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +306
>
System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+336
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig)
+643
>
System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+279
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +444
>
Here is the code I have for the one page test site (using Asp.Net web
application projects).
>
Default.aspx:
>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestWebApp._Default" %>
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="testGrid"></asp:GridView>
</div>
</form>
</body>
</html>
>
Default.aspx.cs
>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
>
namespace TestWebApp
{
public partial class _Default : System.Web.UI.Page
{
public class MyClass
{
public MyClass()
{
name = Guid.NewGuid().ToString();
}
private string name;
>
public string Name
{
get { return name; }
set { name = value; }
}
>
}
>
public void Page_Load(object sender, EventArgs e)
{
testGrid.DataSource = new MyClass();
testGrid.DataBind();
}
>
protected void Page_PreRender(object sender, EventArgs e)
{
}
}
}
>
I have tried adding AllowPartiallyTrustedCallers to the assemblyinfo.cs
file
for the web application, no luck.
Aug 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eiriken | last post by:
Hello everyone, I am using ASP.NET 2 and trying to bind a objectdatasource to a gridview. By doing this the most common way by adding an objectdatasource to the page and by using the wizard to...
0
by: Michael Howes | last post by:
I have a webservice and use WSE so a user can upload a good sized file. The entire ASP.Net projects, web.config sets a Medium trust level IIS is set up to use "Integrated Windows authentication"...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
4
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create...
2
by: RCM | last post by:
I have a very simple gridview that is working fine. My real data is more complicated, but for purposes of my question imagine a grid display that looks like: Audi red heavy Audi blue medium...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
1
by: Mark Olbert | last post by:
I have a GridView as a child control in a custom composite control which is stubornly refusing to databind at design time. I'm convinced I must be missing something about how the databinding process...
7
by: shanthidiana | last post by:
hi All, I am new to dot net... i am learning it and I am doing my masters project in c# dot net with sql server 2000 backend... The issue i am having now is... i am having a gridview, upon...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.