CSharp2014.08.25 13:59




WebBrowser Control을 사용할 때 기본적으로 CSS3 기능이 활성화가 되지 않는다. 이때 레지스터리를 수정하여 활성화를 시켜주면 된다.

http://stackoverflow.com/questions/10236829/webbrowser-component-not-showing-css-3

http://www.pedautreppe.com/post/How-can-we-render-CSS3-in-a-WebBrowser-Control-.aspx

 

참고~~~~

신고




Posted by 금붕어70
CSharp2014.05.19 18:04




오랜 시간을 Log4net을 사용하였지만 항상 아쉬운 점이 있었는데, 상속을 사용한 구조를 만들 때 Base class에 Logger를 한번만 지정하고 파생 클래스에서는 다른 정의 없이 바로 사용하는 것이었습니다.

하지만 이런 구조에서의 문제는 로그가 발생했을 때 이것을 발생시킨 클래스를 알기가 쉽지 않았습니다. 그런데 다른 별도의 방법이 존재하는 군요.

App.config



  
    

 

Child.cs

using log4net;
namespace LogTest
{
    public class Child : Parent
    {
        protected static readonly ILog childlog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public Child()
        {
            //childlog.Info("Child constructed!");
            parentlog.Info("Child constructed -- By ParentLog");
            GrandFatherLog.Info("Child Constructed!-- By GrandFatherLog");
        }
    }
}

 

Parent.cs

using log4net;
using System.Diagnostics;
using System.Reflection;
namespace LogTest
{
    public class Parent : GrandFather
    {
        public Parent() 
        {
            parentlog.Info("Parent constructed!");
            GrandFatherLog.Info("Parent Constructed!-- By GrandFatherLog");
        }
        public static ILog parentlog
        {
            get
            {
                StackFrame sf = new StackFrame(1, false);
                MethodBase methodBase = sf.GetMethod();
                return LogManager.GetLogger(methodBase.DeclaringType);
            }
        }
    }
}

 

GrandFather.cs

using log4net;
using System.Diagnostics;
using System.Reflection;
namespace LogTest
{
    public class GrandFather
    {
        public GrandFather()
        {
            GrandFatherLog.Info("GrandFather Constructed!");
        }
        public static ILog GrandFatherLog
        {
            get
            {
                StackFrame sf = new StackFrame(1, false);
                MethodBase methodBase = sf.GetMethod();
                return LogManager.GetLogger(methodBase.DeclaringType);
            }
        }
    }
}

 

Program.cs

using log4net;
using System;
namespace LogTest
{
    class Program
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Info("Test Start!");
            Child newChild = new Child();
            Console.ReadKey();
        }
    }
}

 

신고




Posted by 금붕어70
CSharp2012.05.16 09:23




Microsoft ASP.NET 2.0 Providers: Introduction

32 out of 48 rated this helpful - Rate this topic

Microsoft Corporation

March 2006

Applies to:
Microsoft ASP.NET 2.0

Summary: Describes the design and operation of the various built-in providers that Microsoft ASP.NET 2.0 uses for state management services. (6 printed pages)

Click here to download the entire series in PDF format Microsoft ASP.NET Providers.pdf.

Contents

Microsoft ASP.NET 2.0 Providers: Introduction
Membership Providers
Role Providers
Site Map Providers
Session State Providers
Profile Providers
Web Event Providers
Web Parts Personalization Providers

Click here to download ProviderToolkitSamples.msi.

Introduction

Microsoft ASP.NET 2.0 includes a number of services that store state in databases and other storage media. For example, the session state service manages per-user session state by storing it in-process (in memory in the application domain of the host application), in memory in an external process (the "state server process"), or in a Microsoft SQL Server database, whereas the membership service stores user names, passwords, and other membership data in Microsoft SQL Server or Microsoft Active Directory.

These and other state management services in ASP.NET 2.0 use the provider model pictured in Figure 1-1 to maximize storage flexibility. Providers abstract storage media in much the same way that device drivers abstract hardware devices. The membership service is equally at home using SQL Server or Active Directory, because ASP.NET 2.0 includes providers for each. Moreover, ASP.NET 2.0 can be extended with custom providers to add support for Web services, Oracle databases, SQL Server databases with custom schemas, and other media not supported by the built-in providers.

Aa478948.asp2prvdr0101(en-us,MSDN.10).gif

Figure 1-1. The ASP.NET 2.0 provider model

Table 1-1 lists the providers that are included with ASP.NET 2.0.

Table 1-1. ASP.NET 2.0 providers

Provider Type Built-In Provider(s)
Membership System.Web.Security.ActiveDirectoryMembershipProvider
System.Web.Security.SqlMembershipProvider
Role management System.Web.Security.AuthorizationStoreRoleProvider
System.Web.Security.SqlRoleProvider
System.Web.Security.WindowsTokenRoleProvider
Site map System.Web.XmlSiteMapProvider
Profile System.Web.Profile.SqlProfileProvider
Session state System.Web.SessionState.InProcSessionStateStore
System.Web.SessionState.OutOfProcSessionStateStore
System.Web.SessionState.SqlSessionStateStore
Web events System.Web.Management.EventLogWebEventProvider
System.Web.Management.SimpleMailWebEventProvider
System.Web.Management.TemplatedMailWebEventProvider
System.Web.Management.SqlWebEventProvider
System.Web.Management.TraceWebEventProvider
System.Web.Management.WmiWebEventProvider
Web Parts personalization System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider
Protected configuration System.Configuration.DPAPIProtectedConfigurationProvider
System.Configuration.RSAProtectedConfigurationProvider

This whitepaper documents the design and operation of many of the built-in providers.

It supplements the providers' source code and it contains helpful insights for developers writing custom providers of their own. For more information on the ASP.NET 2.0 provider model, and for guidance on writing custom providers, visit ASP.NET 2.0 Provider Model: Introduction to the Provider Model.

The SQL Provider Database

Many of the Microsoft ASP.NET 2.0 providers are SQL providers—providers that persist state in SQL Server (or SQL Server Express) databases. The SQL providers include SqlMembershipProvider, SqlRoleProvider, SqlProfileProvider, SqlSessionStateStore, SqlWebEventProvider, and SqlPersonalizationProvider. Each stores data using a predefined schema. The Aspnet_regsql.exe tool that comes with ASP.NET 2.0 creates a SQL Server database with a compatible schema. That database, which is named aspnetdb by default, will hereafter be referred to as the SQL provider database or simply the provider database.

Figure 1-2 shows the structure of the SQL provider database. Some of the tables are provider-specific. The aspnet_Membership table, for example, is used exclusively by SqlMembershipProvider, whereas the aspnet_Roles and aspnet_UsersInRoles tables are used exclusively by SqlRoleProvider.

Click here for larger image

Figure 1-2. The SQL provider database (Click on the image for a larger picture)

Other tables are not provider-specific, but instead exist for the benefit of multiple SQL providers. The aspnet_Applications table is a great example. Many SQL providers support scoping of data through the ApplicationName property, which is initialized from the applicationName configuration attribute supported by many providers . For example, websites that register membership providers with identical applicationName attributes share membership data, whereas websites that register membership providers with unique applicationNames do not. SQL providers that support ApplicationName scoping do so by storing application IDs associated with the records that they create, and by including those application IDs in queries performed on the SQL provider database. Application IDs stored in aspnet_Membership, aspnet_Paths, and other provider-specific tables refer to the aspnet_Applications table, which contains a list of extant application IDs and the corresponding application names. Table 1-2 documents the schema of the aspnet_Applications table. The provider database contains a stored procedure named aspnet_Applications_CreateApplication that providers (or stored procedures) can call to retrieve an application ID from the aspnet_Applications table, or to create a new one if the specified application doesn't exist.

Table 1-2. The aspnet_Applications table

Column Name Column Type Description
ApplicationId uniqueidentifier Application ID
ApplicationName nvarchar(256) Application name
LoweredApplicationName nvarchar(256) Application name (lowercase)
Description nvarchar(256) Application description

aspnet_Users is another example of a table that's shared by SQL providers. It stores core provider-agnostic information regarding users, including user names and user IDs. SqlMembershipProvider stores membership-user data in the aspnet_Membership table, but that table contains a UserId column that refers to the column of the same name in aspnet_Users. Similarly, SqlRoleProvider stores data mapping users to roles in the aspnet_UsersInRoles table, and that table contains both a UserId column referring to the column of the same name in aspnet_Users, and a RoleId column referring to the column of the same name in aspnet_Roles. Table 1-3 documents the schema of the aspnet_Users table.

Table 1-3. The aspnet_Users table

Column Name Column Type Description
ApplicationId uniqueidentifier Application ID
UserId uniqueidentifier User ID
UserName nvarchar(256) User name
LoweredUserName nvarchar(256) User name (lowercase)
MobileAlias nvarchar(16) User's mobile alias (currently not used)
IsAnonymous bit 1=Anonymous user, 0=Not an anonymous user
LastActivityDate datetime Date and time of last activity by this user
Note Developers are sometimes surprised to find that the aspnet_Users table's UserName column contains alphanumeric identifiers (GUIDs) as well as string user names. Records containing GUIDs for user names are created when SqlProfileProvider or SqlPersonalizationProvider persists data on behalf of anonymous users.

The SQL providers never access tables in the provider database directly. Instead, they use stored procedures. When SqlMembershipProvider's CreateUser method is called, for example, it calls a stored procedure named aspnet_Membership_CreateUser to add a new membership user to the provider database. aspnet_Membership_CreateUser adds a record representing that user to the aspnet_Membership table, another record representing that user to the aspnet_Users table, and, if necessary, a record denoting a new application to the aspnet_Applications table. The use of stored procedures hides the database schema from the provider, which simplifies porting SQL providers to other database types (for example, Oracle databases), and to SQL Server databases that utilize custom schemas. Stored procedures that perform multistep updates typically use database transactions to roll back changes if an error occurs before the last step is completed. (There are a few cases in which providers manage transactions themselves in order to support batch deletes.)

SQL Server Express

Rather than use a pre-existing SQL provider database, the Microsoft SQL providers are equally happy to use a database managed by SQL Server Express, herafter referred to as the express database.

Internally, the express database has the same schema as the SQL provider database. The difference between the databases lies in how they're created. The SQL provider database is created externally when you run Aspnet_regsql.exe or an equivalent tool. The express database is created automatically the first time it's needed.

Each Microsoft SQL provider (with the exception of SqlSessionStateStore, which doesn't support express databases) has logic built in to automatically create the express database. The logic lives in a helper class named SqlConnectionHelper. Rather than create SqlConnections from raw connection strings, Microsoft SQL providers pass connection strings to SqlConnectionHelper.GetConnection, as follows:

SqlConnectionHolder holder = SqlConnectionHelper.GetConnection( _sqlConnectionString, true );

SqlConnectionHelper.GetConnection parses the connection string and automatically creates the express database if the connection string meets certain criteria, and if the database doesn't already exist.

Note When a Microsoft SQL provider needs an actual SqlConnection, it extracts it from the Connection property of the SqlConnectionHolder, as follows:

SqlCommand cmd = new SqlCommand("dbo.aspnet_Membership_CreateUser", holder.Connection);

Similarly, it closes the connection by calling SqlConnectionHolder.Close.

The main purpose of the SqlConnectionHolder class is to simplify the security model when SQL providers are used in a website with client impersonation enabled. SqlConnectionHolder encapsulates logic that temporarily reverts the thread identity to that of the current process identity or application impersonation identity when connecting to SQL Server. As a result, SQL providers run with a trusted subsystem model that doesn't require individual users to have access rights to the provider database.

The default LocalSqlServer connection string in Machine.config is an excellent example of a connection string that results in automatic creation of the express database:

data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

The presence of User Instance=true and AttachDBFilename=|DataDirectory| cause SqlConnectionHelper to conclude that the connection string targets SQL Server Express and triggers the database's creation. (The presence of data source=.\SQLEXPRESS in the connection string does not factor into the decision, because SqlConnectionHelper supports non-default as well as default instances of SQL Server Express.) The |DataDirectory| portion of the connection string specifies that the MDF file is located inthe App_Data directory. SqlConnectionHelper derives the database name from the MDF file name. It also creates an App_Data folder to hold the MDF if the folder doesn't already exist.

When SqlConnectionHelper creates the express database, it sets SIZE to 10 (10 MB) and FILEGROWTH to 50%. The database's sort order, case sensitivity, accent sensitivity, and other locale-dependent settings are inherited from the default SQL Server Express instance, which ensures that the database locale is consistent with that of the host computer.

Note The extra overhead incurred by checking for the existence of the express database before using it means that Microsoft SQL providers run marginally slower against SQL Server Express than SQL Server. Hopefully, the small performance loss is offset by the added convenience of automatically created express databases.

Go on to part 2, Membership Providers.

신고




Posted by 금붕어70
CSharp2012.05.11 16:59




Asp.Net MVC 환경에서 .Net 용 DI 툴인 Ninject를 사용하는데 책에서 제시하는 소스가 오류를 내는 군요.

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) 
{
  return controllerType == null
           ? null
           : (IController)ninjectKernel.Get(controllerType);
}

이렇게 하면 Routing 설정이 정확하지 않으면  Controller Not Found 오류가 발생하는 군요.

그래서 한참을 구글링하여 찾은 내용은 다음과 같이 처리 하면 자연스럽게 404 File Not Found 로 떨어지는 군요.

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) 
{
  if (controllerType == null)
  {
    return base.GetControllerInstance(requestContext, controllerType);
  }
  else
  {
    return (IController)ninjectKernel.Get(controllerType);
  }
}
신고




Posted by 금붕어70
CSharp2012.03.09 10:56




윈도우 OS에는 파일의 생성,변경,삭제에 대해서 이벤트를 수신자에게 전달하는 기능이 있습니다. 이중에서 C#에서는 FileSystemWatcher 기능으로 파일의 변경을 감지할 수 있습니다.
 
Case 1:
 1. 기존파일 삭제(Delete Event)
 2. 신규파일 생성(Create Event)
 
기존에 있는 파일의 내용을 변경하여 새로운 내용으로 변경할 때 일반적으로는 다음과 같은 절차로 변경합니다.
 그러나 우리가 원하는 이벤트는 Change 이벤트 1개만 발생하기를 원합니다.
 
Case 2:
 

FileStream fs = null;
StreamWriter sw = null;

fs = new FileStream(txtFileName.Text, FileMode.Open, FileAccess.Write, FileShare.None);
sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(txtOutput.Text);

sw.Flush();
sw.Close();
fs.Close();

 이 경우는 기존파일 100bytes 의 문서이고 변경 내용이 90bytes 인 경우 10bytes 의 쓰레기가 남습니다.
 
Case 3:
 System.IO.Copy,  System.IO.Move 의 사용은 원하지 않는 추가 Change 이벤트가 발생합니다.
 
Case 4:
 마지막 방법은 Dos 의 내장 명령어인 move를 사용하여 업데이트를 하는 방법입니다.
이 경우에 특별한 조건을 만족하면 우리가 원하는 1개의 Change 이벤트만을 발생시킵니다.
 1) 변경할려고 하는 하는 내용을 포함한 파일을 생성합니다.
 -. 변경대상 파일과 이름을 동일하게 합니다.
 -. 변경대상 파일과 같은 Root 디렉토리에 저장합니다. (C:\, D:\....)
 2) Dos 명령어를 사용해서 이동합니다.
 예)  cmd /c move D:\Test1\Test.xml   D:\Test2\Test.xml


그러면 Case 4의 경우를 C#으로 구현해 보겠습니다. C#에서 Dos 내장 명령어의 실행은 cmd.exe 명령어의 파라미터를 통해서 실행합니다.


string strTempFileName = @"C:\Temp\Test1\Test.xml";
string strTempFileName = Path.Combine(strTempFolder, txtFileName.Text);

FileStream fs = null;
StreamWriter sw = null;
fs = new FileStream(strTempFileName, FileMode.Create, FileAccess.Write, FileShare.None);
sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.Write(txtOutput.Text);

sw.Flush();
sw.Close();
fs.Close();

try
{
 System.Diagnostics.Process p = new System.Diagnostics.Process();
 p.StartInfo = new System.Diagnostics.ProcessStartInfo();
 p.StartInfo.FileName = "cmd.exe";
 p.StartInfo.Arguments = String.Format(@"/c move {0} {1}", strTempFileName, txtFileName.Text);
 p.StartInfo.CreateNoWindow = true;
 p.StartInfo.ErrorDialog = false;
 p.StartInfo.RedirectStandardInput = true;
 p.StartInfo.UseShellExecute = false;
 p.Start(); 
}
catch (Exception ex)
{
 txtStatus.AppendText(ex.Message + Environment.NewLine);
}
신고




Posted by 금붕어70