ドメイン アカウントを使用して、IIS で実行されている CRM で認証しています。バックスラッシュがデータベースに返されるとエラーがスローされるため、REMOTE_USER サーバー変数のバックスラッシュを Domain\User Domain_User などの代わりに返すように置き換えたいと考えています。HTTPModule を作成しようとしましたが、次の行で「操作はこのプラットフォームではサポートされていません」というエラーが返されます。
oServerVars["REMOTE_USER"] = remote_user.Replace("\\", "_");
私が使用しているコードは以下のとおりです。
private void Context_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
//Pulling out the Server Variables Collection
NameValueCollection oServerVars = context.Request.ServerVariables;
//Request REMOTE_USER Variable
if (!string.IsNullOrEmpty(oServerVars["REMOTE_USER"]))
{
string remote_user = oServerVars["REMOTE_USER"];
//Locate the server variables field in the collection
oServerVars = (NameValueCollection)context.Request.GetType().GetField("_serverVariables", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(context.Request);
//Locate the readonly fields
PropertyInfo oReadable = oServerVars.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
//Setting the new value
oReadable.SetValue(oServerVars, false, null);
oServerVars["REMOTE_USER"] = remote_user.Replace("\\", "_");
oReadable.SetValue(oServerVars, true, null);
}
}
また、コードを BeginRequest に入れようとしましたが、うまくいきませんでした。それを達成する方法はありますか?