Click here to Skip to main content
15,897,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm getting the below exception when i'm sending mail with the SMTPClient.Send(MailMsg);

"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

I'm able to send the mail from local system, but when i'm sending mail from the website which is hosted in the shared server, i'm getting the above error.

Even i had mentioned the below lines in web.config.
XML
<location allowOverride="false" path="Default Web Site">
    <system.web>
      <securityPolicy>
        <trustLevel name="Full" policyFile="internal"/>
        <trustLevel name="High" policyFile="web_hightrust.config"/>
        <trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
        <trustLevel name="Low" policyFile="web_lowtrust.config"/>
        <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
      </securityPolicy>
      <trust level="Full" originUrl=""/>
    </system.web>
  </location>


Can any one please suggest, where is the mistake?

Thanks in advance,
Varshini M.
Posted

Is this on a public hosting service - 'shared server' suggests it is.
Is the web.config you quote the web.config for your site or the server's top level web.config?
If it's the web.config you have in your development environment, have you made any adjustments to what gets uploaded to your production server?

If the top level web.config doesn't give Full trust - and doesn't contain a location entry with Full Trust for your web site - and has allowOverride set to false - then whatever is in the web.config for your site is irrelevant and you won't have full trust.

On a public shared host, you won't have access to the top level web.config (I hope!) - and your site won't be the "Default Web Site" as specified in the snippet you posted.

My gut reaction is that if you have a SecurityPermission error then you have a trust problem. The web host I use happily puts web sites with problems into Full trust if that solves the problem.

Hope this helps.
 
Share this answer
 
Comments
Sandeep Mewara 3-May-11 1:16am    
my 5!
u can use CASPOL.exe to give full trust to your folder.I also got same problem but due to below link i solved my problem.

I recommend u to just download GUI CASPOL COMMAND GENERATOR from below link
and browse ur folder in it and run,,it will automatically set full trust to your folder.

http://brandonpotter.wordpress.com/2010/01/23/code-access-security-policy-caspol-exe-gui-utility/[^]
 
Share this answer
 
Comments
NuttingCDEF 3-May-11 3:03am    
Yes, if getting enough access to use CASPOL is feasible. But if this is a "website which is hosted in the shared server", it may be that using CASPOL is as impossible as editing the relevant web.config directly. If so, talking to the hosting provider may be the only option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900