简体   繁体   English

Asp 联系页面在本地工作,但不在服务器上

[英]Asp contact page works locally but not on a server

I have an asp website and a contact form in asp that I found online.我在网上找到了一个asp网站和一个asp中的联系表格。 It runs perfectly on the local machine.它在本地机器上完美运行。

I added it to my server to test it live, and it didn't work.我将它添加到我的服务器以对其进行实时测试,但它不起作用。 I got the display message to display the error, and it says this:我收到了显示错误的显示消息,它说:

System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. System.Security.SecurityException:请求类型为“System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的权限失败。 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand() at System.Net.Mail.SmtpClient.Initialize() at System.Net.Mail.SmtpClient..ctor(String host, Int32 port) at contact.btnSubmit_Click(Object sender, EventArgs e) in g:\\pleskvhosts\\myweburl\\httpdocs\\contact.aspx.cs:line 33 The action that failed was: Demand The type of the first permission that failed was: System.Net.Mail.SmtpPermission The Zone of the assembly that failed was: MyComputer在 System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 在 System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 在 System.Security.CodeAccessPermission.Demand() 在 System.Net.Mail。 SmtpClient.Initialize() at System.Net.Mail.SmtpClient..ctor(String host, Int32 port) at contact.btnSubmit_Click(Object sender, EventArgs e) in g:\\pleskvhosts\\myweburl\\httpdocs\\contact.aspx.cs:第 33 行失败的操作是:需求 失败的第一个权限的类型是:System.Net.Mail.SmtpPermission 失败的程序集的区域是:MyComputer

Does anyone know what this means?有谁知道这是什么意思?

My code for contact.aspx.cs is我的 contact.aspx.cs 代码是

protected void btnSubmit_Click(object sender, EventArgs e)
{
    try
    {
        MailMessage mailMsg = new MailMessage();

        mailMsg.From = new MailAddress(TheirEmail.Text);

        mailMsg.To.Add("myemailaddress@gmail.com");

        mailMsg.IsBodyHtml = true;

        mailMsg.Subject = "Contact Question!";

        mailMsg.Body = "Contact Details" + "<b>Name:</b>" + TheirName.Text + " <br/> <b>Email - address :</b>" + TheirEmail.Text + "<br/> <b>Comments :</b>" + Comments.Text;

        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

        mailMsg.Priority = MailPriority.Normal;

        smtp.Credentials = new System.Net.NetworkCredential("myemailaddress@gmail.com", "mypassword");

        smtp.Timeout = 25000;

        smtp.EnableSsl = true;

        smtp.Send(mailMsg);

        TheirEmail.Text = "";
        TheirName.Text = "";
        Comments.Text = "";


        DisplayMessage.Text = "Thank you. Your contact details and feed back has been submitted.";
        DisplayMessage.Visible = true;
    }

    catch (Exception ex)
    {
        DisplayMessage.Text = ex.ToString();
        DisplayMessage.Visible = true;
    }

Make sure your Web.Config file has the trust level set to full :确保您的Web.Config文件的trust level设置为full

<configuration>
  <system.web>
    .....
    <trust level="Full" originUrl=""/>
  </system.web>
</configuration>

For example, if you are using GoDaddy , you must set the following in System.Net.Mail.SmtpClient variable (eg *smtp *):例如,如果您使用GoDaddy ,则必须在System.Net.Mail.SmtpClient变量中设置以下内容(例如 *smtp *):

SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net", 25);
smtp.EnableSsl = false; // check if your ISP supports SSL

You will also need to follow this page here to properly configure Email on GoDaddy .您还需要在此处按照此页面在GoDaddy上正确配置电子邮件。

In some cases, if you cannot achieve full trust , having a lower security level will not allow you to specify an SMTP port.在某些情况下,如果您无法获得full trust ,则较低的安全级别将不允许您指定 SMTP 端口。 Your ISP specifies port 80 , but sometimes you can use the default which is port 25 if 80 doesn't work.您的 ISP 指定端口80 ,但有时您可以使用默认端口 25如果 80 不起作用。

Do this.....做这个.....

mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = relay-hosting.secureserver.net;
smtp.EnableSsl = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM