Email Problem

S

shapper

Hello,

I have a contact form in my web site which is working just fine on my
computer!

When I uploaded my web site to my hosting server I get an error when I
SUBMIT my form, i.e., when I click submit to send the email:

Security Exception
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:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

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) +678
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share) +114

System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(String
streamName) +80

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName, Boolean assertPermissions) +115

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName) +7

System.Configuration.Internal.DelegatingConfigHost.OpenStreamForRead(String
streamName) +10
System.Configuration.UpdateConfigHost.OpenStreamForRead(String
streamName) +42
System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
+443


Does anyone has any idea why is this happening?

Thank You Very Much,

Miguel
 
R

Rad [Visual C# MVP]

Hey shapper,

A litte more info will help
1) Is it a particular form or just any form
2) If it is just one form, what does the code in the submit button do?

Hello,

I have a contact form in my web site which is working just fine on my
computer!

When I uploaded my web site to my hosting server I get an error when I
SUBMIT my form, i.e., when I click submit to send the email:

Security Exception
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:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

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) +678
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share) +114

System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(String
streamName) +80

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName, Boolean assertPermissions) +115

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName) +7

System.Configuration.Internal.DelegatingConfigHost.OpenStreamForRead(String
streamName) +10
System.Configuration.UpdateConfigHost.OpenStreamForRead(String
streamName) +42
System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
+443


Does anyone has any idea why is this happening?

Thank You Very Much,

Miguel
 
S

shapper

Hi,

Maybe the error comes from me getting data from Web.Config?

I have this code inside a custom control but here it is:


1 Private Sub bSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles bSubmit.Click
2
3 ' Create new mail message
4 Dim message As New System.Net.Mail.MailMessage
5
6 ' Define mail message properties
7 With message
8
9 ' Define various properties
10 .To.Add(New System.Net.Mail.MailAddress(Me.ToAddress,
Me.ToName))
11 .Body = tbMessage.Text
12 .IsBodyHtml = True
13
14 ' Define fromMailAddress
15 If Me.NameVisible Then
16 .From = New System.Net.Mail.MailAddress(tbEmail.Text,
tbName.Text)
17 Else
18 .From = New System.Net.Mail.MailAddress(tbEmail.Text)
19 End If
20
21 ' Define subject
22 If Me.SubjectVisible Then
23 .Subject = tbSubject.Text
24 End If
25
26 End With
27
28 ' Create and define the SMTP client
29 Dim smtpClient As New System.Net.Mail.SmtpClient
30
31 ' Create access to configuration file
32 Dim configurationFile As Configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
33
34 ' Create mail settings section group
35 Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
configurationFile.GetSectionGroup("system.net/mailSettings")
36
37 ' Define smtp client properties
38 If Not mailSettings Is Nothing Then
39 With smtpClient
40 .Port = mailSettings.Smtp.Network.Port
41 .Host = mailSettings.Smtp.Network.Host
42 .Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Network.UserName,
mailSettings.Smtp.Network.Password)
43 End With
44 End If
45
46 ' Send the mail message and define sent property
47 Try
48
49 ' Send the mail message
50 smtpClient.Send(message)
51
52 ' Define sent property
53 Me.Sent = True
54
55 Catch ex As Exception
56
57 ' Define sent property
58 Me.Sent = False
59
60 End Try
61
62 ' Raise the OnFormSubmited event
63 RaiseEvent FormSubmited(Me, EventArgs.Empty)
64
65 End Sub

Maybe the problem comes from line 32? I am sure about this ...

Anyway, could someone help me out and send me some sugestions?

Thanks,

Miguel
Hey shapper,

A litte more info will help
1) Is it a particular form or just any form
2) If it is just one form, what does the code in the submit button do?

Hello,

I have a contact form in my web site which is working just fine on my
computer!

When I uploaded my web site to my hosting server I get an error when I
SUBMIT my form, i.e., when I click submit to send the email:

Security Exception
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:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

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) +678
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share) +114

System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(String
streamName) +80

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName, Boolean assertPermissions) +115

System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String
streamName) +7

System.Configuration.Internal.DelegatingConfigHost.OpenStreamForRead(String
streamName) +10
System.Configuration.UpdateConfigHost.OpenStreamForRead(String
streamName) +42
System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
+443


Does anyone has any idea why is this happening?

Thank You Very Much,

Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top