Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / January 2008

Tip: Looking for answers? Try searching our database.

Code Access Security Issue - Hosting .NET Windows Forms Controls i

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
royHe - 23 Jan 2008 02:18 GMT
I am Writing a control that access the webservice to retrieve some data from
SQL server and write into an excel file.  I use
Provider=Microsoft.Jet.OLEDB.4.0 to write the file to Excel file. Test the
control in the windows application, everything works fine, but when host in
IE Brower, I got the flolloing Error:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
  at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)
  at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission
permThatFailed)
  at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle
rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
  at
System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs,
PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
  at BudgetBC.ACCPAC.modMain.RunBatch(String[] CmdArgs)
  at BudgetBC.ACCPAC.ACCPACActExport.Exec_Click(Object sender, EventArgs e)
  at System.Windows.Forms.Control.OnClick(EventArgs e)
  at System.Windows.Forms.Button.OnClick(EventArgs e)
  at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
  at System.Windows.Forms.Control.WndProc(Message& m)
  at System.Windows.Forms.ButtonBase.WndProc(Message& m)
  at System.Windows.Forms.Button.WndProc(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
The action that failed was:
LinkDemand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
Intranet

************** Loaded Assemblies **************
mscorlib
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
ACCPACEXPORT
   Assembly Version: 0.0.0.0
   Win32 Version: n/a
   CodeBase: http://localhost/IRACS/ACCPACEXPORT.dll
----------------------------------------
System.Windows.Forms
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Accessibility
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.42 (RTM.050727-4200)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
Microsoft.VisualBasic
   Assembly Version: 8.0.0.0
   Win32 Version: 8.0.50727.42 (RTM.050727-4200)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
Microsoft.mshtml
   Assembly Version: 7.0.3300.0
   Win32 Version: 7.0.3300.0
   CodeBase:
file:///C:/WINDOWS/assembly/GAC/Microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/Microsoft.mshtml.dll
----------------------------------------
System.Data
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Xml
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Web.Services
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.42 (RTM.050727-4200)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
System.Configuration
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
tuojoqmf
   Assembly Version: 0.0.0.0
   Win32 Version: 2.0.50727.832 (QFE.050727-8300)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
   <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Anyone can help me hout? Thank you advance for your help.

Roy
Jediah L - 25 Jan 2008 15:55 GMT
Use the CASPOLs "Evaluate Assembly" option - pointing to the control out
from the remote server it is being loaded from.

My guess would be that running it in the IE window is putting it into a
different security zone (perhaps the internet zone or at the very least the
intranet zone) compared to the My Computer zone it's likely running as when
you run it from your test windows application.

You will likely need to put a trust in place for the assembly using one of
the various CASPOL mechanisms.

>I am Writing a control that access the webservice to retrieve some data
>from
[quoted text clipped - 153 lines]
>
> Roy
Dominick Baier - 28 Jan 2008 05:52 GMT
Hosting a control in IE puts the control into a different security context
- in your case "intranet":

> The action that failed was:
> LinkDemand
> The type of the first permission that failed was:
> System.Security.Permissions.SecurityPermission
> The Zone of the assembly that failed was:
> Intranet

Certain things are not allowed in this zone out of the box (IIRC e.g. OleDB
access)

You have to make changes to the client's CAS policy to make this work.

Or have a look at the new manifest controls in .NET 3.5

http://blogs.msdn.com/shawnfa/archive/2008/01/24/manifested-controls-redux.aspx

-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

> I am Writing a control that access the webservice to retrieve some
> data from SQL server and write into an excel file.  I use
[quoted text clipped - 163 lines]
>
> Roy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.