分类目录归档:C#

CSharp

WebConfig特殊字符的转义

Web.Config默认编码格式为UTF-8,对于XML文件,要用到实体转义码来替换。对应关系如下:

字符

转义码

& 符号 & &
单引号 '
双引号 "
大于 > >
小于 < &lt;
 

App.config:

 

 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
     </startup>
   <connectionStrings>
     <add name="DBconnString" connectionString="Data Source=.;Initial Catalog=MyTest123456;User ID=sa;PassWord=123&456"/>
   </connectionStrings>
 </configuration>

 

由于数据库连接的密码中含有特殊字符”&”,编译时出现如下如下错误信息:

显然编译器不认识”&456″,怎么解决呢,总不能更换密码吧?

事实上App.config是xml文件,在xml文件中特殊字符要进行HTML转义。

HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用。这些符号是不显示在我们最终看到的网页里的,那如果我们希望在网页中显示这些符号,就要用到HTML转义字符串(Escape Sequence)了

 


HTML特殊转义字符列表

 

最常用的字符实体

显示     说明     实体名称     实体编号

 

         空格     &nbsp;     &#160;

<         小于     &lt;      &#60;

>      大于    &gt;      &#62;

&      &符号    &amp;     &#38;

“      双引号    &quot;     &#34;

©      版权    &copy;    &#169;

®    已注册商标    &reg;    &#174;

™    商标(美国)    ™    &#8482;

×    乘号      &times;    &#215;

÷     除号      &divide;    &#247;

 

所以只要把”&”进行转义就可以了,将PassWord改为PassWord=123&amp;456″成功通过编译。

 

How To: Set the proxy for the WebBrowser control in .NET

Source:https://blogs.msdn.microsoft.com/jpsanders/2011/04/26/how-to-set-the-proxy-for-the-webbrowser-control-in-net/

I see some horrible solutions for this out on the web.  Most involve setting the proxy for the entire machine and then toggling it back off.  Here is a class that will allow you to set it ONLY FOR THE PROCESS that the control is hosted in.  You could call it like this:

WinInetInterop.SetConnectionProxy(“localhost:8888”);

and then restore it to the default set in IE with this call:

// read the default settings for IE and restore these as the proxy
WinInetInterop.RestoreSystemProxy();
Let me know if you thought this was useful! 继续阅读

WinForm应用程序自动升级实现

最近单位开发一个项目,其中需要用到自动升级功能。因为自动升级是一个比较常用的功能,可能会在很多程序中用到,于是,我就想写一个自动升级的组件,在应用程序中,只需要引用这个自动升级组件,并添加少量代码,即可实现自动升级功能。因为我们的程序中可能包含多个exe或者dll文件,所以要支持多文件的更新。 继续阅读

Validate Image extensions

we have checked the posted file of the FileUpload and pass it to the IsImageFile() method that returns a Boolean type for checking the actual type of the posted file. If the file contains image extension such as “jpg”, “gif”, “bmp” and “png” then it will return TRUE else it will return false. 继续阅读

Microsoft Chart Controls

.NET 3.5 发布功能强大的新控件(Winform&WebForm) —— Chart

前言

11月25号,Scott在博客上发布了基于.NET Framework 3.5 SP1的图表控件——Chart,可在WinForm和WebForm下使用!并同时提供了大量的示例…

继续阅读

防止对 Visual Basic .NET 或 C# 代码进行反相工程

摘要

.NET 体系结构的优势之一在于,利用该体系结构构建的程序集包含很多有用的信息,使用中间语言反汇编程序 ILDASM 即可恢复这些信息。但是这样会带来另一个问题,就是可以访问您的二进制代码的人能够以非常近似的手段恢复原始源代码。作者将在文中介绍程序模糊处理,该处理可作为一种阻止反相工程的手段。此外,他们还将讨论可用的不同类型的模糊处理技术,并示范 Visual Studio .NET 2003 中包含的新模糊处理工具。 继续阅读

Some examples of scripting of IIS using ADSI, WMI from VB and C# including the new Microsoft.Web.Administration namespace

Below are some simple examples of how to talk to IIS via ADSI, WMI and the new IIS 7 only .NET Managed Provider.

The IIS ADSI Provider

The IIS ADSI provider exposes COM Automation objects that you can use within command-line scripts, ASP pages, or custom applications to change IIS configuration values stored in the IIS metabase. IIS ADSI objects can be accessed and manipulated by any language that supports automation, such as Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft JScript®, Perl, Microsoft Active Server Pages (ASP), Visual Basic, Java, or Microsoft C++.

继续阅读

Cool new IIS7 Features and APIs

Cool new IIS7 Features and APIs

IIS7 is a major upgrade of IIS, and will ship in both Windows Vista as well as Windows Longhorn Server. It includes a ton of new functionality, including some very rich integration with ASP.NET. This includes: 继续阅读