2012-11-01 2 views
1

모든 것이 좋지만 web.config가이 이상한 오류를 표시합니다.web.config 구성 오류

web.config의 문자열 목록이 양호 할 경우 어떻게해야합니까?

에러 :
구성 오류 설명 : 오류가이 요청을 제공하는 데 필요한 구성 파일을 처리하는 동안 일어났다. 아래의 특정 오류 세부 정보를 검토하고 구성 파일을 적절히 수정하십시오.

Parser Error Message: Unrecognized configuration section stringlist. 

Source Error: 


Line 6:  <connectionStrings/> 
Line 7:  
Line 8:   <stringlist key="SmtpServers"> 
Line 9:    <stringlistItem value="smtp.transip.nl" /> 
Line 10:   <stringlistItem value="localhost" /> 


Source File: C:\local\vCardGenerator.Website\vCardGenerator.Website\web.config Line: 8 

의 Web.config :

<stringlist key="SmtpServers"> 
     <stringlistItem value="smtp.transip.nl" /> 
     <stringlistItem value="localhost" /> 
    </stringlist> 

등급 :

using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Web.Configuration; 
using System.Net.Mail; 
using System.Net.Configuration; 
using Compulutions.Net; 
using Compulutions.Web; 
using System.IO; 
using System.Web.Mail; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Web.Services.Description; 

// System.Web.Mail.SmtpMail.SmtpServer 
// using System.Web.Mail.SmtpClient; 

namespace vCardGenerator.Website.Masterpage 
{ 
    public class SendvCard 
    { // 
     public void MailvCard(string recipient, string filename) 
     { 
     Mailer smtp = new Mailer("smtpServers"); 

     /* SMTP - port 25 */ 

     smtp.AddAttachment(filename); //.vcf file Path 
     smtp.FromAddress = new MailAddress("[email protected]"); 
     smtp.Subject = "vCard"; 
     smtp.MailBody = "There is a vCard waiting for you in the attachment!"; 
     smtp.AddRecipient(recipient); 

#if !DEBUG 
     try 
     { 
#endif 
      smtp.SendMail(); 
#if !DEBUG 
     } 

     catch (Exception ex) 
     { 
      Response.Write("Exception Occured: " + ex); 
       //Responds.Write("Sending vCard Failed, Please try again!") 
     } 
#endif 
     } 
    } 
} 

비슷한 질문은 내 설명에 적합하지 않습니다. 나는 SendvCard.cs의 인스턴스를 생성하고 클래스 (MailvCard)의 전송 방식 자체 aspx.cs

호출 한 :

 // Calls the method at the class 
      smtp.MailvCard("[email protected]", "C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf"); 
     } 

다른/더 많은 정보를 제공 할 의사가 필요한 경우 .

감사

+2

'stringlist'와'stringlistitem'은 무엇입니까? 이것들을 유효한 설정 섹션으로 만들거나 등록 했습니까? –

+0

configSections 노드에 stringlist를 추가하는 것을 잊었습니까? –

+0

예, 유효한 구성 섹션으로 등록했습니다. – Lobato

답변

2

당신이 그것을 선언하지 않고 새로운 섹션 (stringlist)를 만든 때문에 오류를보고있다. 먼저 지금처럼의 Web.config의 configSections 영역에 섹션을 선언해야합니다 :

<stringlist key="SmtpServers"> 
    <stringlistItem value="smtp.transip.nl" /> 
    <stringlistItem value="localhost" /> 
    </stringlist> 

예는이 링크를 참조뿐만 아니라 :

<configSections> 
    <section name="stringlist" type="System.Configuration.NameValueSectionHandler,System"/> 
</configSections> 

구성의 루트 아래에 stringlist를 넣어 이 값에 액세스하는 방법 : Customizing SectionGroups and Sections in Web.config

또한이를 달성하는 방법이 많이 있습니다. MailSettings 같은 Rashedul.Rubel 제안했다.

1
//you can try by using the following smtp configuration in web.config 

<system.net> 
    <mailSettings> 
     <smtp> 
     <network host="SMTPServer" port="" userName="username" password="password" /> 
     </smtp> 
    </mailSettings> 
    </system.net> 
    <appSettings> 
    <add key="Email" value="[email protected]"/> 
    </appSettings> 

//where host=your server name, port=server machines port number 

//and in code behind write the code as follows: 

     string fromEmail = ConfigurationManager.AppSettings["Email"].ToString(); 
    string toEmail = txtEmail.Text; 
    MailMessage message = new MailMessage(fromEmailAddress, toEmailAddress); 
    message.Subject = txtSubject.Text; 
    message.Body = txtBody.Text; 

    SmtpClient smtp = new SmtpClient(); 
    smtp.Send(message); 
+0

정보를 제공해 주셔서 감사합니다. 양식이 아니며 메일 + 첨부 파일을 (자동으로) 보내고 버튼 (보내기) 할 곳의 텍스트 상자입니다. – Lobato

0
Action Mailer can be used to send email. email can be sent with attachment without using form. 
web config configuration for the smtp: 

    <system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network"> 
     <network host="smtp.gmail.com" port="25" userName="username" password="password" defaultCredentials="false" enableSsl="true"/> 
     </smtp> 
    </mailSettings> 
    </system.net> 

configure smtp in IIS 

attachment can be done using Attachments.Inline["" + fileName] = System.IO.File.ReadAllBytes(filePath); 

for more information see the link below: 
http://ratiyaranmal.blogspot.com/2012/06/send-email-in-mvc-using-actionmailer.html