Security exception using System.Net.Mail in a class library

Security exception using System.Net.Mail in a class library

Post by venne » Wed, 20 Sep 2006 22:47:49


Hi group,
I am currently developing two websites that will work together, but for
several reasons are seperated into two projects. I am developing in
ASP.NET 2.0 using VS2005. In my solution I have 3 projects: the two
web sites and a class library that contains some code shared by both
websites.

I have noticed that if I try to use certain libraries (notably
System.Net.Mail and System.Data.SqlClient) I get a Security Exception.
The text of the exeption for System.Net.Mail follows:

System.Security.SecurityException: Request for the permission of type
'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I have played around with Attributes trying to get the CLR to grant the
assembly the required permissions I added the following line to the
class where I have the call to the SmtpClient object, but to no avail:

[assembly:
SmtpPermission(System.Security.Permissions.SecurityAction.RequestOptional,
Unrestricted=true)]

Does anybody know how I can make use of System.Net.Mail from a class
library?

Thanks,
Eric
 
 
 

1. "An unhandled exception of type 'System.Security.SecurityException' " VB .NET

2. How to send mail bodies with german umlauts using System.Net.Mail?

Hello,

I'm using VS 2005 and I need to send a mail body which contains german
umlauts (.

When I receive the mail in Outlook 2003 (english operating system) I always
get a '|' or other similar symbols instead of the expected umlaut.

I'm using Sstem.Net.Mail and I already tried something like this:
string body = "this is some sample HTML text";

System.Net.Mail.AlternateView htmlView =
System.Net.Mail.AlternateView.CreateAlternateViewFromString(body,
Encoding.Unicode, "text/html");

mail.AlternateViews.Add(htmlView);

and also this:

string body = "this is some sample HTML text";

System.Net.Mail.AlternateView htmlView =
System.Net.Mail.AlternateView.CreateAlternateViewFromString(body,
Encoding.GetEncoding("iso-8859-1"), "text/html");

mail.AlternateViews.Add(htmlView);

In both cases I receive the wrong message body without the umlauts.

What am I doing wrong? Am I missing something?

Many thanks in advance,

Roberto Rocco.

3. Copy all data from a:Class A's fields to the namesake fields of b:Class B.

4. Using Windows-Control-Library in IE (getting Security-Exception)

5. Outlook Client cannot assign Mails to CRM User, SYSTEM is used ins

6. System.Net.Mail.SmtpException how do I send mail in .Net 2.0

7. Cannot instantiate .NET Class Library to expose webservice client library via Interop to ASP

8. Unresolved externals when using STL in a .NET class library

9. message box on client side using class library of .net

10. using a C# class library in both COM and .NET code?

11. Question regarding the System.Net.Mail and System.Net.Mime namespa

12. Using .NET Class Library within classic ASP

13. Class Library for Asp.Net 2.0 (using C# in VS.Net 2005 Standard)

14. Cannot instantiate .NET Class Library to expose webservice client library