PC Review


Reply
Thread Tools Rate Thread

Catch security exception

 
 
William Stacey
Guest
Posts: n/a
 
      10th Jan 2004
How do you catch the security exception that may occur when running .Net
from a network drive and you don't have the proper Trust level? TIA. Get
this messagebox that I can't seem to catch:

Common Language Runtime Debugging Servi...
Application has generated an exception that could not be handled.
Process id=blah, Thread id=...
Click OK to terminate the application.
Click CANCEL to debug the application.
--
William Stacey, MVP



 
Reply With Quote
 
 
 
 
MSFT
Guest
Posts: n/a
 
      12th Jan 2004
Hi William,

As I understand, you want to catch the securityexception in your
application which occur when running .Net from a network drive. Besides
Try..Catch statement, we also can set a Application's OnThreadException to
catch an unexpect exception:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformsapplicationclassonthreadexceptiontopic.asp

It is worthy metioned that this only work when you run the executable file.
If you run the application from VS.NET IDE, it doesn't work since VS.NET
IDE already handled it.

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
William Stacey
Guest
Posts: n/a
 
      12th Jan 2004
Thanks. I tried the try catch and the OnThreadException and can't seem to
catch this security exception. Me thinks it is caught before main is even
entered. Can you think of other? TIA

--
William Stacey, MVP

"MSFT" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi William,
>
> As I understand, you want to catch the securityexception in your
> application which occur when running .Net from a network drive. Besides
> Try..Catch statement, we also can set a Application's OnThreadException to
> catch an unexpect exception:
>
>

http://msdn.microsoft.com/library/de...us/cpref/html/
> frlrfsystemwindowsformsapplicationclassonthreadexceptiontopic.asp
>
> It is worthy metioned that this only work when you run the executable

file.
> If you run the application from VS.NET IDE, it doesn't work since VS.NET
> IDE already handled it.
>
> Hope this help,
>
> Luke
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>



 
Reply With Quote
 
MSFT
Guest
Posts: n/a
 
      13th Jan 2004
Hi William,

Regarding on this issue, you may assert all permission required by the
application first in the main sub. For exmaple, if the application will
open a file:

Dim fileIOPerm1 As New FileIOPermission(FileIOPermissionAccess.AllAccess,
"C:\testio.txt")

Try
fileIOPerm1.Assert()
Catch ex As Security.SecurityException

Console.WriteLine(ex.Message)

End Try

If the assembly didn't have the permission, a exception will be generated
and this exception can be caught by the try statement.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to catch Security exception alf Microsoft ASP .NET 0 5th Mar 2007 06:03 PM
catch sql exception gerry Microsoft ASP .NET 7 6th Jul 2006 11:53 PM
Difference between try{}catch{} and try{}catch(Exception e){} ? Mr Flibble Microsoft C# .NET 7 22nd Jun 2006 04:25 PM
when to catch an exception... Dan Bass Microsoft C# .NET 7 16th Dec 2004 05:10 PM
ASP catch exception eddie wang Microsoft ASP .NET 0 24th Jul 2003 06:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.