MSDN说<supportedRuntime>配置元素可以包含可选属性sku.我完全理解如何使用它,但什么是SKU?我的意思是它是一个首字母缩略词,如果是,它代表什么?
我需要通过签名和加密来保护我的网络令牌.我编写了下一行代码:
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.Name, owner.Name),
new Claim(ClaimTypes.Role, owner.RoleClaimType),
new Claim("custom claim type", "custom content")
}),
TokenIssuerName = "self",
AppliesToAddress = "http://www.example.com",
Lifetime = new Lifetime(now, now.AddSeconds(60 * 3)),
EncryptingCredentials = new X509EncryptingCredentials(new X509Certificate2(cert)),
SigningCredentials = new X509SigningCredentials(cert1)
};
var token = (JwtSecurityToken)tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);
Run Code Online (Sandbox Code Playgroud)
所以,我正在使用一些生成的证书makecert.exe.然后我用另一个读取令牌字符串JwtSecurityTokenHandler:
var tokenHandlerDecr = new JwtSecurityTokenHandler();
var tok = tokenHandlerDecr.ReadToken(tokenString);
Run Code Online (Sandbox Code Playgroud)
并且令牌内容未加密(我可以tok在调试器下看到变量中的json ).我究竟做错了什么?如何加密令牌数据?
我想知道,是否有可能翻译包含'?'的正则表达式?T-SQL LIKE模式中的(在可选项之前)?没有DB侧的任何操作.例如,"^31-?4".我可以将它分成几个子句,但如果正则表达式包含很多'?' 这不方便.
我想知道为什么该XmlDictionary.Add()方法返回XmlDictionaryString.在什么情况下这个对象会有用?
我有一个IIS托管的WCF服务,我正在尝试使用Directory.Exists()方法.如果传递不存在的网络位置,则此方法将挂起.我用谷歌搜索它,发现由于Directory.Exists()内部实现,它"有点好" .但我写了一个简单的控制台应用程序,它做同样的Directory.Exists()事情,永远不会挂起,总是返回' false'.我在我的(管理员)帐户下运行应用程序,IIS池在"网络服务"下运行.
你有什么想法吗?在服务或控制台应用程序中执行相同操作有什么区别?
我有以下代码:
public class Temp<T, TMetadata>
{
[ImportMany]
private IEnumerable<Lazy<T, TMetadata>> plugins;
public Temp(string path)
{
AggregateCatalog aggregateCatalog = new AggregateCatalog();
aggregateCatalog.Catalogs.Add(new DirectoryCatalog(path));
CompositionContainer container = new CompositionContainer(aggregateCatalog);
container.ComposeParts(this);
}
public T GetPlugin(Predicate<TMetadata> predicate)
{
Lazy<T, TMetadata> pluginInfo;
try
{
pluginInfo = plugins.SingleOrDefault(p => predicate(p.Metadata));
}
catch
{
// throw some exception
}
if (pluginInfo == null)
{
// throw some exception
}
return Clone(pluginInfo.Value); // -> this produces errors
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个对象,Temp我GetPlugin()从多个线程调用.有时我会遇到奇怪的构图错误,我没有找到重现的方法.例如:
"System.InvalidOperationException: Stack empty.
at …Run Code Online (Sandbox Code Playgroud) 我有一个 Windows 服务,其中包含一个单例,该单例又使用一些记录器、消息队列侦听器等。这些类实现了IDisposable. 我应该IDisposable在单例本身中实现还是做其他事情来确保服务停止/崩溃后,本机资源一切正常?单例是这样实现的:
public class Temp
{
private static readonly Lazy<Temp> instance = new Lazy<Temp>(() => new Temp());
private Temp()
{
// create IDisposable objects which use native resources
}
public static Temp Instance
{
get
{
return instance.Value;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个动态创建的程序集,一个模块,一个类和一个动态生成的方法。
AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(...);
ModuleBuilder module = assembly.DefineDynamicModule(...);
TypeBuilder tb = module.DefineType(...);
MethodBuilder mb = tb.DefineMethod(...);
ILGenerator gen = mb.GetILGenerator();
Run Code Online (Sandbox Code Playgroud)
如何调试使用生成的方法代码ILGenerator?我使用Visual Studio 2012调试器,但它只是逐步执行方法调用。
我使用以下方法对数据库执行查询并读取数据:
using(SqlConnection connection = new SqlConnection("Connection string"))
{
connection.Open();
using(SqlCommand command = new SqlCommand("SELECT * FROM TableName", connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
// read and process data somehow (possible source of exceptions)
} // <- reader hangs here if exception occurs
}
}
Run Code Online (Sandbox Code Playgroud)
在读取和处理数据时,可能会发生一些异常.问题是当抛出异常时DataReader挂起Close()电话.你有什么想法吗??? 以及如何以正确的方式解决这个问题?当我在处理读卡器之前编写try..catch..finally块而不是using和调用时,问题就消失了.command.Cancel()finally
工作版本:
using(SqlConnection connection = new SqlConnection("Connection string"))
{
connection.Open();
using(SqlCommand command = new SqlCommand("SELECT * FROM TableName", connection))
{
SqlDataReader reader = …Run Code Online (Sandbox Code Playgroud) 我想知道为什么从base64字符串转换为不同的字符串返回相等的字节数组?
const string s1 = "dg==";
const string s2 = "dq==";
byte[] a1 = Convert.FromBase64String(s1);
byte[] a2 = Convert.FromBase64String(s2);
Console.WriteLine(a1.SequenceEqual(a2)); // prints "True".
Run Code Online (Sandbox Code Playgroud) 有没有办法用.NET创建多页tiff与jpeg压缩?我可以使用LZW压缩创建tiff,但文件非常大.看起来像EncoderValue枚举(我用来设置压缩)甚至没有合适的成员.
为什么Resharper在下面的代码示例中警告我"访问处理关闭":
using (SqlCommand command = new SqlCommand())
{
command.Parameters.Add("@temp", SqlDbType.VarChar);
Action<string> action = str =>
{
command.Parameters["@temp"].Value = string.Empty;
};
}
Run Code Online (Sandbox Code Playgroud)
我不使用委托外部using声明......如何解决这个问题?
我发现以下编译器生成的代码使用DotPeek分析.NET程序集之一:
[UnsafeValueType, NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
internal struct DWriteTextAnalysisNode<MS::Internal::Text::TextInterface::Native::IDWriteNumberSubstitution *>
{
}
Run Code Online (Sandbox Code Playgroud)
我想知道它意味着什么?如何在C#中重写它?特别是这部分:
<MS::Internal::Text::TextInterface::Native::IDWriteNumberSubstitution *>
Run Code Online (Sandbox Code Playgroud)