ASP联系页面本地工作,但不是服务器上 [英] Asp contact page works locally but not on a server

查看:135
本文介绍了ASP联系页面本地工作,但不是服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp网站,在ASP中的联系人形式,我在网上找到。它完美地运行在本地机器上。

我把它添加到我的服务器,以带电测试它,它没有工作。我得到的消息显示,以显示错误,和它说的:


  

System.Security.SecurityException:请求类型的权限
  System.Net.Mail.SmtpPermission,系统,版本= 4.0.0.0,
  文化=中性公钥= b77a5c561934e089'失败。在
  System.Security。codeAccessSecurityEngine.Check(对象的需求,
  StackCrawlMark&安培; stackMark,布尔isPermSet)在
  System.Security。codeAccessSecurityEngine.Check(codeAccessPermission
  帽,StackCrawlMark&安培; stackMark)在
  System.Security。codeAccessPermission.Demand()在
  System.Net.Mail.SmtpClient.Initialize()在
  System.Net.Mail.SmtpClient..ctor(字符串主机,端口的Int32)的
  contact.btnSubmit_Click(对象发件人,EventArgs e)在
  G:\\ pleskvhosts \\ myweburl \\的httpdocs \\ contact.aspx.cs:33行行动
  失败是:需求类型失败的第一个权限的
  是:大会的System.Net.Mail.SmtpPermission区的
  失败是:我的电脑


有谁知道这是什么意思?

我的code为contact.aspx.cs是

 保护无效btnSubmit_Click(对象发件人,EventArgs的发送)
{
    尝试
    {
        MAILMSG MAILMESSAGE新= MAILMESSAGE();        mailMsg.From =新的MailAddress(TheirEmail.Text);        mailMsg.To.Add(myemailaddress@gmail.com);        mailMsg.IsBodyHtml = TRUE;        mailMsg.Subject =联系问题!        mailMsg.Body =联系方式+< B>名称:LT; / B>中+ TheirName.Text +< BR />< B>电子邮件 - 地址:< / B>中+ TheirEmail.Text +< BR />< B>注释:其中; / B>中+ Comments.Text;        SmtpClient SMTP =新SmtpClient(smtp.gmail.com,587);        mailMsg.Priority = MailPriority.Normal;        smtp.Credentials =新System.Net.NetworkCredential(myemailaddress@gmail.com,输入mypassword);        smtp.Timeout = 25000;        smtp.EnableSsl = TRUE;        smtp.Send(MAILMSG);        TheirEmail.Text =;
        TheirName.Text =;
        Comments.Text =;
        DisplayMessage.Text =谢谢您的详细联系方式和反馈已提交。
        DisplayMessage.Visible = TRUE;
    }    赶上(异常前)
    {
        DisplayMessage.Text = ex.ToString();
        DisplayMessage.Visible = TRUE;
    }


解决方案

请确保您的 的Web.Config 文件的 信任级别 设置为 完全

 <结构>
  <&的System.Web GT;
    .....
    <信任级别=全originUrl =/>
  < /system.web>
< /结构>

例如,如果您使用的是 GoDaddy的,您必须在 System.Net.Mail.SmtpClient 变量(如:* SMTP *):

  SmtpClient SMTP =新SmtpClient(relay-hosting.secureserver.net,25);
smtp.EnableSsl = FALSE; //检查,如果您的ISP支持SSL


  

您还需要按照此页 这里 GoDaddy的正确配置电子邮件。


在某些情况下,如果不能达到完全信任,具有较低的安全级别将不会允许你指定一个SMTP端口。您的ISP指定端口的 80 ,但有时你可以使用默认的是端口25 如果80不工作。

I have an asp website and a contact form in asp that I found online. 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. 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

Does anyone know what this means?

My code for contact.aspx.cs is

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:

<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 (e.g. *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.

In some cases, if you cannot achieve full trust, having a lower security level will not allow you to specify an SMTP port. Your ISP specifies port 80, but sometimes you can use the default which is port 25 if 80 doesnt work.

这篇关于ASP联系页面本地工作,但不是服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆