2010. 5. 7. 17:35

관리하는 서버가 많을 경우 손쉽게 서버의 계정 비밀번호를 변경하고 싶을 수 있다.
이런 고민에서 시작해서 만들어 보았다. 
(여러 네트워크 환경에서 확인 해보지 못했고 동일 네트워크 환경에서는 정상적으로 동작하는 것을 확인했다.)

1. 이전 비밀번호를 알고 새 비밀번호로 변경하고자 할 경우
using System.DirectoryServices; // 참조추가를 해야 사용 가능하다.
...
string userPath = string.Format("WinNT://{0}/{1}", TargetServer, UserName);
using (DirectoryEntry userEntry = new DirectoryEntry(userPath))
{
object[] password = new object[] { this.txtOldPw.Text, this.txtNewPw.Text };
object ret = userEntry.Invoke("ChangePassword", password);
userEntry.CommitChanges();
}


2. 이전 비밀번호를 몰라도 새 비밀번호로 리셋하고 싶을 경우
string userPath = string.Format("WinNT://{0}/{1}", TargetServer , UserName);
using (DirectoryEntry userEntry = new DirectoryEntry(userPath))
{
object[] password = new object[] { this.txtNewPw2.Text };
object ret = userEntry.Invoke("SetPassword", password);
userEntry.CommitChanges();
}


참고로 TargetServer는 IP로 접근할 경우 오류가 발생하였고.. 컴퓨터명으로 접근해야 정상적으로 처리가 되었다.
그리고 administrator 계정의 비밀번호도 변경이 가능했다.

샘플

참고

Posted by CoolDragon
2010. 5. 4. 11:17

RegExp를 이용하여 문자열 정규식 검사를 할 수 있다.

<%
Dim StringToSearch 
StringToSearch = "http://www.foo.com"

Set RegularExpressionObject = New RegExp

With RegularExpressionObject
    .Pattern = ".com"
    .IgnoreCase = True
    .Global = True
End With

expressionmatch = RegularExpressionObject.Test(StringToSearch)
If expressionmatch Then
    Response.Write RegularExpressionObject.Pattern & " was found in " & StringToSearch
Else
    Response.Write RegularExpressionObject.Pattern & " was not found in " & StringToSearch
End If
%>


RegExp 개체에는 Test 수를 제외한 Execute Replace 함수도 포함하고 있다. 

자세한 자료는 아래 링크를 참고한다.



Posted by CoolDragon
2010. 5. 3. 17:50
Posted by CoolDragon
2010. 5. 3. 15:48
출처 : http://virtuelvis.com/archives/2004/02/css-ie-only

IE 버전별 CSS 적용하기
<link rel="stylesheet" type="text/css" href="common.css" />

<!--[if IE]>
  <link rel="stylesheet" type="text/css" href="all-ie.css" />
<![endif]-->

<!--[if IE 6]>
  <link rel="stylesheet" type="text/css" href="ie-6.0.css" />
<![endif]-->

<!--[if lt IE 6]>
  <link rel="stylesheet" type="text/css" href="ie-5.0+5.5.css" />
<![endif]-->
<!--[if IE]>
  <style type="text/css">
    @import url(ie-styles.css);
  </style>
<![endif]-->

Posted by CoolDragon
2010. 4. 30. 17:27
솔직히 지네릭은 기존에 있는것만 사용했지
내가 만들어 쓴적은 거의(?) 없는 듯 하다.
잘만하면 정말 괜찮은 녀석인데 ㅋㅋ

생각만 잘하면 확장성 있게 쓸 수 있지 않을까 싶다.
    public static T IIF<T>(bool compare, T a, T b)
    {
        return compare ? a : b;
    }
   (위 샘플은 3항 연산자를 써도 될듯 하지만 말이다...ㅋ)
Posted by CoolDragon
2010. 4. 29. 17:09
어디서나 빠지지 않고 사용되는 페이징

참고 안하고 만들여보려니 절라 빡시단걸 알게 됐다.
이거 잘 만든 소스인지는 잘 모르겠네만.. 내가 만든거니 이거 쓸란다.ㅋㅋ

[결과]


[샘플]
Posted by CoolDragon
2010. 4. 29. 10:07
출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=18&MAEULNo=8&no=1228&ref=1228
--------------------------------------------------------------------------------------------------

//양력은 음력으로변환 테스트
private void button1_Click(object sender, EventArgs e)
{
    label1.Text =음력변환(2007, 1, 1);
    label2.Text = 음력변환(DateTime.Now);
}

//음력을 양력으로 변환 테스트
private void button2_Click(object sender, EventArgs e)
{
    label2.Text = 양력변환(2006,11,13,false).ToShortDateString();
}

private string 음력변환(DateTime dt)
{
    int n윤월;
    int n음력년, n음력월, n음력일;
    bool b윤달 = false;
    System.Globalization.KoreanLunisolarCalendar 음력 =
new System.Globalization.KoreanLunisolarCalendar();

    n음력년 = 음력.GetYear(dt);
    n음력월 = 음력.GetMonth(dt);
    n음력일 = 음력.GetDayOfMonth(dt);
    if (음력.GetMonthsInYear(n음력년) > 12)             //1년이 12이상이면 윤달이 있음..
    {
b윤달 = 음력.IsLeapMonth(n음력년, n음력월);     //윤월인지
n윤월 = 음력.GetLeapMonth(n음력년);             //년도의 윤달이 몇월인지?
if (n음력월 >= n윤월)                           //달이 윤월보다 같거나 크면 -1을 함 즉 윤8은->9 이기때문
   n음력월--;
    }
    return n음력년.ToString() + "-" + (b윤달 ? "*" : "") + n음력월.ToString() + "-" + n음력일.ToString();
}

private string 음력변환(int n양력년, int n양력월, int n양력일)
{
    DateTime dTemp = new DateTime(n양력년, n양력월, n양력일); //양력
    return 음력변환(dTemp);
}

private DateTime 양력변환(int n음력년, int n음력월, int n음력일, bool b달)
{
    int n윤월;
    System.Globalization.KoreanLunisolarCalendar 음력 =
new System.Globalization.KoreanLunisolarCalendar();

    if (음력.GetMonthsInYear(n음력년) > 12)
    {
n윤월 = 음력.GetLeapMonth(n음력년);
if (b달)
   n음력월++;
if (n음력월 > n윤월)
   n음력월++;
    }
    return 음력.ToDateTime(n음력년, n음력월, n음력일, 0, 0, 0, 0);
}



Posted by CoolDragon
2010. 4. 26. 17:31
HTTP Header를 이용한 파일 다운로드

ASP.NET도  거의 코드가 동일한 가능하다.

Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End
Posted by CoolDragon
2010. 4. 20. 18:10
asp에서 다른 도메인(Cross Domain)의 데이터를 주고 받기 위한 방법으로도 사용된다.
(다른 방법으로는 JSONP를 이용할 수 있다.)

1. C#. XMLWebService 프로젝트로 XML 웹서비스를 개발한다.
  - 도메인 : ws.cooldragon.co.kr
2. asp에서 웹서비스를 호출하는 클라이언트 페이지를 개발한다.
  - 도메인 : www.cooldragon.co.kr
3. 개발된 사이트를 IIS를 설정한다.
4. 브라우저에서 테스트 해본다.
※ ws.cooldragon.co.kr, www.cooldragon.co.kr 은 가상의 도메인이며
   예외 처리는 개발자의 몫으로 돌린다. ^^;;
-------------------------------------------------------------------------

1. [XML 웹서비스 개발]
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string SayHello(string name)
        {
            return "Hello " + name;
        }

        [WebMethod]
        public int Sum(int x, int y)
        {
            return x + y;
        }

        [WebMethod]
        public int Subtract(int x, int y)
        {
            return x - y;
        }
    }


2. [asp 개발]
<%
' 구현부
Dim reqTy
Dim url
Dim param

url = "http://ws.cooldragon.co.kr/Service1.asmx/SayHello"
param = "name=cooldragon"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/Sum"
param = "x=1&y=2"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/Subtract"
param = "x=1&y=2"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/HelloWorld"
param = ""
Response.Write "result=" & CallWebService(url, param) & "<br/>"
...

'웹서비스 호출 함수
Function CallWebService(url, param)

    Dim result
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.XMLHTTP")
    xmlhttp.Open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send param
    
    result = xmlhttp.responseText
    set xmlhttp = nothing    
           
    CallWebService = result

End Function 
%>


3. IIS 설정
   - www.cooldragon.co.kr

  - ws.cooldragon.co.kr

4. 실행결과를 확인할 수 있다.


참고URL :
http://www.codeproject.com/KB/asp/Web_Service_Call_From_ASP.aspx
Posted by CoolDragon
2010. 4. 20. 12:17
공통모듈(컴포넌트)이 개발되면 여러 비지니스 로직에서 사용할 수 있다.

예를 들면 (COM+과 같은) 암호화 컴포넌트가 있는경우
암호화 컴포넌트는 asp, asp.net, sql server 2005(sqlclr을 통하여)에서 동일하게 사용이 가능하다.
성능상 로컬 라이브러리보다는 떨어지겠지만 개발생산성은 클 것이라 생각된다.

이러한 측면에서 SQLCLR은 개발자에게 이러한 것을 제공하며 제작하는 방법을 작성해본다~

1. VS2008 시작
2. 프로젝트 생성 
   C# > 데이터베이스 > SQL Server 프로젝트
3. SP 또는 Function을 개발 후 빌드
public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString Hello(string str)
    {
        // 여기에 코드를 입력합니다.
        return new SqlString("Hello " + str);
    }
};

4. SQL Server에서 어셈블리 등록
  1) clr 권한생성
EXEC sp_configure 'clr enabled' , '1' 
go 
reconfigure; 

  2) 어셈블리 등록
CREATE ASSEMBLY 등록명 FROM '경로\dll명'

  3) 개발 SP 또는 Function 등록
CREATE FUNCTION Hello 
@str NVARCHAR(1000)
RETURNS NVARCHAR(1000)
AS EXTERNAL NAME SqlServerProject1.UserDefinedFunctions.Hello

참고 URL
http://msdn.microsoft.com/en-us/library/ms345135(SQL.90).aspx
Posted by CoolDragon