分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年7月20日
I will talk today about a very common issue we face when we try to use .NET's RSACryptoServiceProvider class in ASP.NET.When we try to create a new RSACryptoServiceProvider object in this scenario, we may get the following exception: "System.Security.Cryptography.CryptographicException: The system cannot find the file specified".By using my CryptoAPI Tracer script we can take a look to the CryptoAPI calls that .NET is making behind the scenes. Thanks to this script we will be able to see the exact API that is failing and the exact error (which most of the time .NET masks).In our case, the API that fails is CryptAcquireContext, and it fails with error #2 (ERROR_FILE_NOT_FOUND). According to CryptAcquireContext documentation, this error means the following:"The profile of the user is not loaded and cannot be found. This happens when the application impersonates a user, for example, the IUSR_ComputerName account."By default, ASP.NET won't load the user profile. Take a look to the parameters of the problematic CryptAcquireContext call as being shown in the log file that my script generated. If this API is not being called with CRYPT_MACHINE_KEYSET (to use the machine profile) or CRYPT_VERIFYCONTEXT (to use temporary key stores), it will try to access the key stores in the user profile, and it will fail because its not loaded.
分类: SoftWare
发布: yaosansi
浏览:
日期: 2010年7月10日
在nginx中配置proxy_pass时,如果是按照^~匹配路径时要注意proxy_pass后的url最后的/当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走如果没有/,则会把匹配的路径部分也给代理走01.location ^~ /static_js/ 02.{ 03.proxy_cache js_cache; 04.proxy_set_header Host js.test.com; 05.proxy_pass http://js.test.com/; 06.}如上面的配置,如果请求的url是http://servername/static_js/test.html会被代理成http://js.test.com/test.html而如果这么配置:01.location ^~ /static_js/ 02.{ 03.proxy_cache js_cache; 04.proxy_set_header Host js.test.com; 05.proxy_pass http://js.test.com;06.}
分类: SoftWare
发布: yaosansi
浏览:
日期: 2010年7月10日
在使用nginx时对于upstream的server的测试中发现,nginx默认对其使用的是基于IP的转发,这就意味着对于同IP、同端口、不同域名时无法进行转发。在官方WIKI:http://wiki.nginx.org/NginxHttpUpstreamModule没有查到相应的解决方案。在GOOGLE上查到多篇几乎无人问同样的问题,最终发现Timo的这篇文章:nginx单一端口域名转发,也进一步证实了yaosansi的猜测是正确的.以下引用了Timo的原文中的解决方案:
分类: SoftWare
发布: yaosansi
浏览:
日期: 2010年7月6日
原文:http://www.yaosansi.com/post/1453.html
How to sign EXE using signtool with Verisign SPC and PVK on the command line?
run "signtool signwizard" to start the signing wizard.
1. File Selection: Choose the EXE you wish to sign (ie, yaosansi.com.exe)
2. Signing Options: Choose "Custom"
3. Signature Certificate: Click "Select from File" and choose "mycredentials.spc"
4. Private Key: Select "Private key file on disk" and choose "myprivatekey.pvk"
- Leave CSP at "Microsoft Strong Cryptographic Provider"
- Leave Provider Type at "RSA FULL"
5. Private Key Password: Enter "xxxxxxxxxx"
6. Hash Algorithm: Leave it at 'sha1'
7. Additional Certificates:
- Leave it at "All certificates in the certification path, including the root"
- Leave it at "No additional certificates"
8. Data Description: Enter the following:
- Description:yaosansi.com
- Web Location: http://www.yaosansi.com
9. Digital Signature Wizard:
- Enable "Add a timestamp to the data"
- Timestamp service URL: http://timestamp.verisign.com/scripts/timstamp.dll
- 这里还有两个免费的时间戳服务器
a.http://timestamp.wosign.com/timestamp
b.http://timestamp.comodoca.com/authenticode
* Note: This enables the signature to work forever; not sure
what this means but the Verisign guy was pretty excited about it
10. Review and click OK
11. Enter private key password: Enter "xxxxxxxxxxx"
12. Done!
相关文章:
白话数字签名(番外篇)——签名EXE文件(上)
白话数字签名(番外篇)——签名EXE文件(下)
签名工具 (SignTool.exe)
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年6月17日
在 .NET Framework 3.5 beta 时,微软曾引入了一个新的包 System.Numerics,其中包含了大整数(BigInteger)类,不过可惜在后来的接近发布时,这个包又移除了。现在 .NET Framework 4.0 又重新将它请了回来。而且这次的正式版本中不会再次移除了。这对 .NET 开发者算是一个好事,但如果只有使用 .NET Framework 4.0 的用户才能享受到这个包,还是不太完美,毕竟现在大多数 .NET 开发还停留在 2.0 或 3.5 的阶段。
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年6月16日
Introduction to Second VersionThis is a new, extended, improved version of my original article. This was (and is) my first (and only until now) CodeProject article. It was well rated, but at the same time a lot of people suggested corrections, alternatives and improvements. So I will use all this new info to show you a better way to do the same thing. Every improvement in my code was suggested by someone else, so this is some sort of collective writing. I'm just compiling things that you can read in the forum. But since I don't always read the forum, it makes sense to me to make some "text oriented maintenance". I will try to give everyone his own credit.There are two solutions now inside the download, one for VS2008 with four projects (Desktop and Compact Framework for C# 3.5 and C# 2.0) and another one for VS2005 with four projects (Desktop and Compact Framework for C# 2.0, two different ways to solve the problem for each).At the very end of the article, you will find what I think now is the "official" way (the Microsoft way) to solve this problem. I didn't know about this method until a couple of people post about it in the forum. At least, read that (click here). But I will stick to my way of solving this issue. The following text is pretty much the exact text from the original article; new text begins below the second horizontal line. Enjoy.
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年5月28日
Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluationIf you ever try to debug a multi-threaded Windows Forms application, today's blog is for you. A customer asked me about this issue, and since I have also run into this problem, I decided to talk about it. What is func eval?If you already know what func eval is, or don't care, skip to the bottom.For the rest of us, I wanted to give some background. Func Eval is short for 'function evaluation'. The idea is this: instead of just reading data out of the debuggee process to fill out the watch window, the debugger actually causes code to run inside the debuggee process. It does this by hijacking the stopped thread, and running something entirely different on that thread. Func eval has been a feature of the Visual Studio debugger for a while now.
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年5月28日
随着网站访问量的增加,很多大流量网站都使用了LazyLoad延迟加载技术,特别是图片较多的网站,如:淘宝、土豆等。 在包含很多大图片长页面中延迟加载图片可以加快页面加载速度. 浏览器将会在加载可见图片之后即进入就绪状态. 在某些情况下还可以帮助降低服务器负担.
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年5月26日
Win32应用程序主要有两种类型:控制台应用程序(Console)和窗体程序(Winform),他们使用不同的方式处理应用程序退出。要强制窗体程序(Winform)退出,你需要发送WM_CLOSE消息到主窗口句柄。.NET中可以使用Application.ApplicationExit或Form.Close。在控制台应用程序,这点有所不同。控制台应用程序有点模仿DOS控制台应用程序,通常是在应用程序退出时,进程(命令)执行结束或Ctrl - C被按下。
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年4月29日
项目需要动态生成一些类,现总结以下几种方式:1.永春博客里提供的将string动态编译类的方式2.使用Emit动态创建类,并添加实例成员,属性,方法等
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年4月29日
应用程序体系结构在我专攻代码之前,我想谈谈我尝试做的事。您可能记得,SuperGraph 让您从函数列表中进行选择。我希望能够在具体的目录中放置外接程序程序集,让 SuperGraph 检测它们,加载它们,并找到它们中包含的所有函数。如果 SuperGraph 自己能完成此操作则不需要单独的 AppDomain。Assembly.Load() 通常运行良好,但程序集无法独立卸载(只有 AppDomain 可以卸载)。这意味着如果您正在编写服务器,而且您希望用户无需启动和停止服务器即能更新他们的外接程序,那么您将无法使用默认的 AppDomain 实现此任务。要实现此功能,我们将在一个独立的 AppDomain 中加载所有外接程序程序集。当添加或修改文件时,我们将卸载 AppDomain,创建新的 AppDomain,然后将当前文件加载到其中。这样,一切就都完美无缺了。
分类: C#|DOTNET
发布: yaosansi
浏览:
日期: 2010年4月29日
在C++中加载和卸载DLL是一件很容易的事,LoadLibrary和FreeLibrary让你能够轻易的在程序中加载DLL,然后在任何地方卸载。在C#中我们也能使用Assembly.LoadFile实现动态加载DLL,但是当你试图卸载时,你会很惊讶的发现Assembly没有提供任何卸载的方法。这是由于托管代码的自动垃圾回收机制会做这件事情,所以C#不提供释放资源的函数,一切由垃圾回收来做。