I have PasswordRecovery control as follows
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server" UserNameTitleText="">
<MailDefinition BodyFileName="~/ForgotPasswordMail.txt" From="<my mail id>" Subject="Here is your Password"></MailDefinition></asp:PasswordRecovery>
Problem is, when I complete PasswordRecovery wizard (user name, security question etc) and finally click on Submit, I get following exception.
(Dont forget to read the note at the end)
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
[No relevant source lines] |
Source File: App_Web_egyncoen.4.cs
Line: 0
Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +59
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +684
System.IO.FileStream..ctor(String path, FileMode mode) +64
System.Net.Mail.SmtpClient.GetFileMailWriter(String pickupDirectory) +234
System.Net.Mail.SmtpClient.Send(MailMessage message) +2004
System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +653
|
Please note that, the exception thrown here is really misleading. Because, I can easily do following code in Page_Load of the same page and it works (spits out the contents of file)
Response.Write(File.ReadAllText(Server.MapPath(this.PasswordRecovery1.MailDefinition.BodyFileName)));
Does anyone have any idea whats happening here?