私のカスタムセキュリティ属性を実装しようとしています。これは、DLLが署名されカスタムセキュリティ属性c'torで無効なmscorlib例外c'tor
System.IO.FileLoadException occurred
Message=The given assembly name or codebase, 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', was invalid.
Source=WcfRoleProviderTestService
StackTrace:
at SecLib.SecPermissionAttribute..ctor(SecurityAction action)
at WcfRoleProviderTestService.Service1.GetData(Int32 value) in D:\TestProjects\WcfRoleProviderTestService\WcfRoleProviderTestService\Service1.svc.cs:line 19
InnerException:
c'tor私は属性で例外を持っているいくつかの理由今
[Serializable]
[ComVisible(true)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class SecPermissionAttribute : CodeAccessSecurityAttribute
{
public SecPermissionAttribute(SecurityAction action) : base(action) { }
public override System.Security.IPermission CreatePermission()
{
IPermission perm = new PrincipalPermission(PermissionState.Unrestricted);
return perm;
}
}
のために非常に簡単です。セキュリティ上の問題があるようですが、わかりません。ところで、私はPrincipalPermissionAttributeを使用しようとしましたが正常に動作します。 私はVS 2010、FW 4.0を使用していますが、属性はWCFサービスでまとまっています 私はいくつかの助けを得ることを非常にうれしく思います。
私のサービスの構成が、私はWCFサービスを使用するように設定されている場合のみ、Windows XPでは、IISバージョン5.1上とWindows Server 2008 R2 IISV7.5上の両方のエラーを持って、次の
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0" />
<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES"
defaultProvider="MyRoleProvider">
<providers>
<clear />
<add connectionStringName="Service1" applicationName="InfraTest"
writeExceptionsToEventLog="false" name="MyRoleProvider" type="SecLib.MyRoleProvider, SecLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=798c04e15cff851a" />
</providers>
</roleManager>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBindingConfiguration" closeTimeout="00:01:00"
sendTimeout="00:10:00" maxBufferSize="524288" maxReceivedMessageSize="524288">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfRoleProviderTestService.Service1"
behaviorConfiguration="BasicHttpServiceBehavior" >
<endpoint name="BasicHttpEndpoint"
contract="WcfRoleProviderTestService.IService1"
address="WcfAuthenticationTest"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBindingConfiguration" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfRoleProviderTestService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BasicHttpServiceBehavior">
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="MyRoleProvider" impersonateCallerForAllOperations="true" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
ですWindows認証(上記の設定を参照)。もっと興味深い事実は、属性がSystem.Security.Permissions.SecurityAction.Demand
セキュリティアクションで使用されている場合にのみ、エラーが発生したということです。
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
[SecPermission(System.Security.Permissions.SecurityAction.Demand)]
public string GetData(int value)
{
string userName = ServiceSecurityContext.Current.WindowsIdentity.Name;
return string.Format("You entered: {0}, User {1}", value, userName);
}
他のオプションも正常に動作します。おかげさまで
残念ながら、私は問題を再現できないようです。属性はサービスプロジェクトまたは別のDLLで宣言されていますか? DLLが署名されていると言うと、どのDLLが署名されていて、どのような署名(厳密な名前または認証コード)ですか?また、コードのどの部分に属性を適用しましたか? –
こんにちは@ニコール、私は、別々のdllとサービスdllの両方を試して、結果は同じです。今のところ、単純化するために、属性はサービスと同じdllで定義され、dllは文字列名(* .snkファイル)で署名されています。この属性は、Serviceメソッド(実装であり、契約ではない)に適用されます。 –
私はまだ問題を再現することはできません。どのようにサービスをホストしていますか?また、デフォルトの動作、有効化などから変更を加えましたか? –