c# - Asp contact page works locally but not on a server -
c# - Asp contact page works locally but not on a server -
i have asp website , contact form in asp found online. runs on local machine.
i added server test live, , didn't work. got display message display error, , says this:
system.security.securityexception: request permission of type 'system.net.mail.smtppermission, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089' failed. @ 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() @ system.net.mail.smtpclient..ctor(string host, int32 port) @ contact.btnsubmit_click(object sender, eventargs e) in g:\pleskvhosts\myweburl\httpdocs\contact.aspx.cs:line 33 action failed was: demand type of first permission failed was: system.net.mail.smtppermission zone of assembly failed was: mycomputer
does know means?
my code contact.aspx.cs is
protected void btnsubmit_click(object sender, eventargs e) {      seek     {         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. contact details , feed has been submitted.";         displaymessage.visible = true;     }       grab (exception ex)     {         displaymessage.text = ex.tostring();         displaymessage.visible = true;     }       
make sure web.config file has trust level set full:
<configuration>   <system.web>     .....     <trust level="full" originurl=""/>   </system.web> </configuration>    for example, if using godaddy, must set  next in system.net.mail.smtpclient variable (e.g. *smtp *):
smtpclient smtp = new smtpclient("relay-hosting.secureserver.net", 25); smtp.enablessl = false; // check if isp supports ssl       you need follow page here configure email on godaddy.
in cases, if cannot  accomplish full trust, having lower security level not allow specify smtp port. isp specifies port 80, can  utilize default port 25 if 80 doesnt work.
 c# asp.net 
 
Comments
Post a Comment