我有一个[AllowPartiallyTrustedCallers]类库,包含System.DataAnnotations.ValidationAttribute的子类型.该库用于WCF服务的合同类型.
在.NET 2/3.5中,这很好用.但是,从.NET 4.0开始,在Visual Studio调试器中运行服务的客户端会导致异常" 类型的违反继承安全规则:'(我的ValidationAttribute的子类型)'.派生类型必须与基类型的安全可访问性匹配或者不太容易访问. "(System.TypeLoadException)
仅当满足以下所有条件时,才会出现错误:
基本上,在Visual Studio.NET 2010中:
.
using System;
[assembly: System.Security.AllowPartiallyTrustedCallers()]
namespace TestingVaidationAttributeSecurity
{
public class MyValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{ }
[MyValidation]
public class FooBar
{ }
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ValidationAttribute IsCritical: {0}",
typeof(System.ComponentModel.DataAnnotations.ValidationAttribute).IsSecurityCritical);
FooBar fb = new FooBar();
fb.GetType().GetCustomAttributes(true);
Console.WriteLine("Press enter to end.");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
按Ctrl-F5(无需调试即可启动),一切正常,无异常...
奇怪的是,根据您运行程序的方式(F5或Ctrl + F5),ValidationAttribute将是或将不是安全关键.如上面代码中的Console.WriteLine所示.但话说回来,这似乎与其他属性(和类型?)一起发生.
现在问题......
为什么在从ValidationAttribute继承时会出现此行为,但在从System.Attribute继承时却没有?(使用Reflector我在ValidationAttribute类或它的程序集中找不到特殊设置)
我该怎么做才能解决这个问题?如何保持MyValidationAttribute继承自AllowPartiallyTrustedCallers程序集中的ValidationAttribute而不将其标记为SecurityCritical,仍然使用新的.NET 4级别2安全模型并仍使用VS.NET调试主机(或其他主机)?
非常感谢!鲁迪
我有以下重写规则:
<rule name="First Rule" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Tracking/(.*)" ignoreCase="true" />
<action type="Rewrite" url="http://www.example.com/" />
</rule>
Run Code Online (Sandbox Code Playgroud)
这将失败,调用http://www.myserver.com/Tracking/123会返回404。
但是,如果我将操作类型更改为“重定向”,则该规则突然可以正常工作,执行重定向:
<rule name="First Rule" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Tracking/(.*)" ignoreCase="true" />
<action type="Redirect" url="http://www.example.com/" />
</rule>
Run Code Online (Sandbox Code Playgroud)
但是我需要一个重写规则,因为我需要一个到内部服务器的反向代理。
我正在Windows 2008R2服务器(IIS 7.5)上工作,已安装“ IIS URL重写模块2”,...
重写规则有什么问题?