2003/10/24

Referrer값 체크로 특정파일에 직접 접근 거부

레퍼러값을 체크하는 방법 2가지 입니다. 먼저, 레퍼러값이 null 값일경우 Default.aspx 페이지로 리다이렉팅. 만일 레퍼러값이 있을경우 현재, 사이트의 도메인과 레퍼러주소의 도메인이 다를경우 다시 Redirect 를 합니다. 바로 Redirect 를 해도 되지만, 자바스크립트로 Alert 를 띄운후 처리..


public void UrlReferrerCheck(string refferUrl) {
        if (Request.UrlReferrer == null) {
            string script = "< script>alert('직접 접근할 수 없습니다!!');" + 
"location.href='/Default.aspx';
            "; Page.RegisterClientScriptBlock("
            done ", script);
            //Response.Redirect(refferUrl);

        } else {
            string refer = Request.UrlReferrer.ToString();
            string ServerPath = Request.Url.ToString();
            ServerPath = ServerPath.Substring(0, ServerPath.LastIndexOf(" / "));
            if (refer.IndexOf(ServerPath) == -1) {
                string script = " < script> alert('직접 접근할 수 없습니다!!');
                " + "
                location.href = '/Default.aspx';
                "; Page.RegisterClientScriptBlock("
                done ", script); //Response.Redirect(refferUrl); } } }

Web.Config 에서 DB연결문 설정

ASP.NET(C#) 에서 DB커넥션 부분은 전역으로 설정하는 코드로 웹 Root에 있는 Web.Config 파일에서 아래 부분을 등록하면 됩니다.

 <? xml version="1.0" encoding="utf-8" ?>
     <configuration>
         <appSettings>
             < add key="ConnectionString" 
value="server=192.168.1.200;database=db_name;user                                    
              id=db_id;password=db_password;Network                                     
              Library=DBMSSOCN">
                 </add> </appSettings> < system.web> .......... 계속......

실제 사용되는 부분에서는 다음과 같이 하면 됩니다.

private void LoadData() {
    string ConnectStr = ConfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection Con = new SqlConnection(ConnectStr);
    SqlCommand Cmd = new SqlCommand();
    Cmd.Connection = Con;...............코드 계속...
}


ASP.NET 메일발송 예제 코드

다음은 ASP.NET(C#) 에서 메일을 발송하는 예제코드 입니다.


using System.Web.Mail;
private void SmtpMailSend() {
    MailMessage mail = new MailMessage();
    mail.From = "보내는 사람";
    mail.To = "받는사람";
    mail.Cc = "참조";
    mail.Subject = "메일 제목";
    mail.Body = "메일 본문 내용";
    mail.BodyFormat = MailFormat.Html;
    //메일 Fotmat 형식
    mail.Priority = MailPriority.High;
    //메일 중요도
    SmtpMail.Send(mail);
    //메일 발송
}


가장 많이 본 글