「.NET」カテゴリーアーカイブ
Visual Studio 2008 ショートカット キー
認証Cookieにsecureオプションを付ける
web.configで認証Cookieにsecureオプションを付ける。
<?xml version="1.0" encoding="shift_jis"?>
<configuration>
<system.web>
.... (中略) ....
<authentication mode="Forms">
<forms name="NETWSSample"
loginUrl="Login/Login.aspx"
protection="All"
requireSSL="true"
timeout="30" path="/" />
</authentication>
.... (中略) ....
</system.web>
</configuration>
認証CookieにHttpOnly属性やsecureオプションを付ける。
using System.Web.Security;
protected void Application_EndRequest(Object sender, EventArgs e)
{
string authCookieName = FormsAuthentication.FormsCookieName;
foreach (string sCookie in Response.Cookies)
{
if (sCookie == authCookieName)
{
// クロスサイトスクリプティング脆弱性に対する多重防衛
Response.Cookies[sCookie].Path += ";HttpOnly";
// SSLセッション外に認証クッキー情報を出さない
// (.NET Framework 1.0用)
// Response.Cookies[sCookie].Secure = true;
}
}
}
※ HttpOnly属性を付与すると、document.cookieプロパティからクッキー情報を取り出せなくなるため、安全性が高まる。ただしHttpOnly属性は、IE6SP1以降でしかサポートされていない。
参考: 「.NETエンタープライズWebアプリケーション開発技術大全Vol.4 セキュアアプリケーション設計編」4.2.6
Visual Studio 2005でイミディエイトウィンドウを開く
Visual Studio 2005でデバッグ中にイミディエイトウィンドウを開くには、
「表示」>「その他のウィンドウ」>「コマンドウィンドウ」でコマンドウィンドウを開き、immedと入力する。
>immed
Windows サービスを柔軟に管理するサービスマネージャの製作
Windows サービスを柔軟に管理するサービスマネージャの製作:パート1 - japan.internet.com デベロッパー
Windows サービスを柔軟に管理するサービスマネージャの製作:パート2 - japan.internet.com デベロッパー
AppDomain、AppDomainSetupの使用方法が分かるサンプルがある。
// create the service app domain
AppDomain svcDomain = null;
try
{
AppDomainSetup setup = new AppDomainSetup();
// use the process base directory as the new domain base and bin path
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
setup.PrivateBinPath = setup.ApplicationBase;
// use the assembly full name as friendly name
setup.ApplicationName = asmName.FullName;
// the base will be the shadow copy 'from' directory
setup.ShadowCopyDirectories = setup.ApplicationBase;
// enable shadow copying
setup.ShadowCopyFiles = "true";
// create the domain with no CAS evidence
svcDomain = AppDomain.CreateDomain(asmName.FullName, null, setup);
}
catch (Exception ex)
{
Logger.LogException(
new ApplicationException(
String.Format("Could not create an AppDomain for '{0}'; bypassing that assembly.",
asmName.FullName), ex));
return;
}
// Get remote service handler
RemoteServiceHandler svc = null;
try
{
// This call will actually create an instance
// of the service handler in the service domain
// and return a remoting proxy for us to act on.
// This is important because we don't want to
// load any type info from the service assembly
// into this assembly
svc = (RemoteServiceHandler)
svcDomain.CreateInstanceFromAndUnwrap(
svcDomain.BaseDirectory + "\\ServiceBroker.dll",
"ServiceBroker.RemoteServiceHandler");
}
catch (Exception ex)
{
// unload domain
AppDomain.Unload(svcDomain);
Logger.LogException(
new AssemblyLoadException(
"Could not load ServiceBroker remote service handler, bypassing that file.",
asmName.FullName, ex));
return;
}
これは、被管理サービスの実行に使う新しいAppDomainをセットアップするコードです。AppDomainSetupオブジェクトを使用しているのは、AppDomain.CreateDomainのオーバーロードにはないオプションがあるためです。ここでは、ディレクトリプロパティを、現アプリケーションディレクトリを指し示すように設定することと、ファイルのシャドウコピーを作成するよう指示することが重要です。シャドウコピーを作成することによって、アセンブリがアプリケーションディレクトリでロックされることを防止できます。ここで例外がスローされることはまずないと思われますが、それでも、何が起こったかをログに記録するためと、スレッドを例外で終わらせないために、例外を正確にキャッチするようにしました。アプリケーションにユーザインタフェースがないときは、こうやって例外をキャッチし、ログに記録することをお勧めします。
他のAppDomainからロードされたアセンブリの設定ファイルにアクセスする
2005-11-15 - Kazzzの日記
AppDomainを生成する際のセットアップオブジェクトである、AppDomainSetupクラスのConfigurationFileプロパティに設定ファイルのパスをセットする。
.NETでアセンブリバインドのエラーログを有効にするには
アセンブリ バインドのエラー ログを有効にするには、以下のレジストリ値をセットする。
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion] "EnableLog"=dword:00000001
上記内容を拡張子.regのファイル名で保存してダブルクリックすれば、レジストリに登録できる。
オフにするには、このレジストリ値をregeditで削除する。
Assembly probing, Fusion and fuslogvw in 5 minutes - B# .NET Blog