2005/07/12
[Asp.Net] Application_Error 를 통한 오류처리
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError();
string err = "<b>Error Caught in Application_Error event</b><hr><br>" +
"<br><b>Error in: </b>" + Request.Url.ToString() +
"<br><b>Error Message: </b>" + objErr.Message.ToString()+
"<br><b>Stack Trace:</b><br>" +
Server.GetLastError().ToString();
//이벤트로그에 기록
EventLog.WriteEntry("Project.AppEvent.aspx",err,EventLogEntryType.Error);
//해당 페이지에 오류내용 출력
Response.Write(err);
Server.ClearError();
}
위와 같이 처리시, 해당 오류가 발생한 페이지에 오류내용을 출력하며, 이벤트로그에 해당내용을 기록하게 됩니다.
위 err 내용은 디자인은 해당 웹페이지에 맞게 변경하면 됩니다.
오류발생시 특정 디자인된 페이지로 이동하게 할려면 Web.config 에 다음을 추가하면 됩니다.
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
</customErrors>
각 오류코드 마다 다른 페이지로 이동하게 할경우는 다음과 같게 하면 됩니다.
<customErrors defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>
[Asp.Net] 웹 페이지 스크랩핑
//필요 네임스페이스
using System.Net
using System.IO
public String GetHtmlPage(string strURL)
{
String strResult;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
//스트림으로 받아옴
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
2005/07/11
터미널서버(Terminal Server)의 포트를 변경하는 방법
기본적으로 터미널 서버와 Windows 2000 / Windows Server 2003 터미널 서비스는 클라이언트 연결에 TCP 포트 3389를 사용합니다. 이 값은 변경하지 않는 것이 좋지만, 이 포트를 변경해야 할 경우에는 다음 방법을 참고하시면 됩니다.
서버쪽 변경부분
1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
2. "PortNumber" 하위 키를 찾아 값이 (3389)의 16진수 값인 00000D3D인지 확인합니다. 10진수로 포트 번호를 수정하고 새 값을 저장합니다.
만약 터미널서버에서 특정연결을 만들었다면, 특정연결명의 포트번호도 변경하시면 됩니다.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\
연결
"PortNumber" 하위 키를 찾아 값이 (3389)의 16진수 값인 00000D3D인지 확인합니다. 10진수로 포트 번호를 수정하고 새 값을 저장합니다.
클라이언트 변경부분
1. 원격데스크톱연결 프로그램에서 127.0.0.1:◯와 같이 접속한다.
2. 커넥션파일을 이용할경우 노트패드에서 "Server Port=3389"를 "Server Port=◯"로 변경
3. 웹 ActiveX 클라이언트는
1. 터미널서비스웹디렉토리\TsWeb 폴더의 Default.htm 파일을 찾습니다.
2. 메모장이나 다른 텍스트 편집기에서 Default.htm을 엽니다.
3. "MsRdpClient.AdvancedSettings2"로 시작하는 항목을 찾습니다.
4. 이러한 항목 뒤에 아래의 행을 추가합니다.
MsRdpClient.AdvancedSettings2.RDPPort = ◯
10-TechNetB_masthead_ltr.gif
값 없는 문자열은 Length로 검사로 속도향상
/*******************************************************************
* 문자열이 있는지 검사할 때 흔히 if (문자열개체 != "")나
* if (문자열개체 != Stirng.Empty)를 쓰는데 이럴 경우 불필요한 오버헤드가 생기지만,
* Length 속성은 개체가 생성될때 설정되므로
* if (문자열개체.Length != 0 )로 해서 값만 비교해서 보다 빠르게 검사할 수 있습니다.
* ******************************************************************/
using System;
namespace StringEmptyVSStringLength
{
/// <summary>
/// Class1에 대한 요약 설명입니다.
/// </summary>
class Class1
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 여기에 응용 프로그램을 시작하는 코드를 추가합니다.
//
string notEmptyString = "값이 있는 문자열";
// IL_000c: call bool [mscorlib]System.String::op_Inequality(string, string)
if (notEmptyString != String.Empty)
{
}
//IL_0014: callvirt instance int32 [mscorlib]System.String::get_Length()
if (notEmptyString.Length != 0)
{
}
}
}
}
IL 코드로는 1가지 명령어지만
"if (notEmptyString != String.Empty)"에서는 12가지 내부 개체의 메서드를 사용해 비교하려는 양쪽의 문자열을 정렬하고 서로 일일히 비교하지만,
i"f (notEmptyString.Length != 0)"에서는 단순이 변수에 값이 0이냐만 비교하기 때문에 속도가 빠를수 밖에 없죠.
실행해 시간을 검사하면 아래와 같은 차이를 보입니다. 단위는 (Microseconds)
742.4 if (notEmptyString != String.Empty)
0.7 if (notEmptyString.Length != 0)
- 출처 : KNUG (한국 닷넷 사용자 모임; Korea .NET User Group)
문자열 비교에 "=="과 "Equals" 속도 비교
* 저번에 본 봐와 같이 ==(IL : op_Equality)에는 12개의 메서드가 사용되지만
* Equals 매서드는 2 가지만 사용되더군요.
* 따라서 문자열 비교할 때는 Equals메서드를 사용해 비교하세요.
using System;
namespace EqualsVs__
{
/// <summary>
/// Class1에 대한 요약 설명입니다.
/// </summary>
class Class1
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string strCompared = "문자열";
//IL_000c: call bool [mscorlib]System.String::op_Equality(string, string)
//사용 메서드 수 : 12개
//시간 : 7453.4
if (strCompared == "문자열")
Console.WriteLine("True");
// IL_0023: callvirt instance bool [mscorlib]System.String::Equals(string)
//사용 메서드 수 : 2개
//시간 : 37.9
if (strCompared.Equals("문자열"))
Console.WriteLine("True");
}
}
}
덧붙여서.. int,double... 의 실수와 연관있는형은 ==가 훨빠릅니다. 단 스트링비교는 반드시 equal 로 하시는 습관을 들이십시요. 얼마안된다 안된다 생각하실수도 있겠지만.. 저거 하나가 여러게 모이면 확연히 표가 납니다...
- 출처 : KNUG (한국 닷넷 사용자 모임; Korea .NET User Group)
http://www.devpia.com/Forum/BoardView.aspx?no=46109&ref=46109&forumname=CSHARP_QA
C# / SQL 에서 Timestamp 변환
using System;
class DateTimeTest
{
static void Main(string[] args)
{
DateTime d1;
DateTime d2;
TimeSpan d3;
int timeStamp;
d1 = DateTime.Parse("1970-01-01 09:00:00"); // 한국시간 기준
d2 = DateTime.Now;
d3 = d2 - d1;
timeStamp = Convert.ToInt32(d3.TotalSeconds); // timestamp로 변환
Console.WriteLine(timeStamp);
Console.WriteLine(d1.AddSeconds(timeStamp)); // 다시 날짜로 변환
}
}
다음코드는 MSSQL에서 OpenQuery 등을 통해서 연동시 변환코드 입니다.
DECLARE @base datetime
SET @base = '1970-01-01 09:00:00'
DATEADD(DateTime컬럼, TimeStamp값 , convert(datetime, @base))
Windows Server 2003 CD 레이블 표
| Acronyms and Abbreviations | |
|---|---|
| CCP | Compliance Checking Program (Upgrade Version) |
| CHK | Checked Build |
| EVL | Evaluation Version |
| FPP | Full Packaged Product (Retail Version) |
| MPC | Microsoft Product Code |
| OEM | Original Equipment Manufacturer |
| PID | Product ID After the Product Key is validated in the Setup program, the Setup program builds a unique PID which is assigned to the computer. A PID contains the Microsoft Product Code (MPC) and the three characters channel ID value. |
| RTM | Release To Manufacturing |
| SEL | Select (License for 250 or more PCs) |
| SLP | System-Locked Preinstallation Royalty OEM vendors can distribute Windows products by using System-Locked Preinstallation Product Keys so that end users can bypass product activations. |
| VLK | Volume License (Product) Key |
| VOL | Volume (License) |
| WPA | Windows Product Activation |
가장 많이 본 글
-
입력된 문자열을 지정된 길이로 자르는 함수. 2byte 문자열 입력도 계산됨. Function packString ( ByVal strString, ByVal intWidth) ON ERROR RESUME NEXT ...
-
CVE-2019-1166 | Windows NTLM 변조 취약성 https://portal.msrc.microsoft.com/ko-KR/security-guidance/advisory/CVE-2019-1166 CVE-2019-1230 | Hype...
-
키움증권 API 이용해서 직접 개발한 닷넷 기반 주식 자동 매매 GUI 프로그램의, 동작 모니터링과 자동 제어가 필요해서 위해서 참조했던 코드. 실행된 GUI 프로그램에서, 특정 핸들 개체(예를 들면 버튼)가 존재하는지 확인 후, 해당 개체에 ...