by jkeen
8. August 2009 12:58
在Stockholm LPMS, ODMS 项目进行瑞典语版本本地化过程中,发现了HTMLEncode的问题。
GridView控件自动将BoundField的内容进行HTMLEncode,(默认BoundField.HTMLEncode=true;)瑞典语中含有拉丁字符,这种字符有可能会被格式化成一串特殊的字符。规则见MSDN:
If the string to be encoded is DBCS, HTMLEncode converts characters as follows:
-
All extended characters are converted.
-
Any ASCII code character whose code is greater-than or equal to 0x80 is converted to &#<number>, where <number> is the ASCII character value.
-
Half-width Katakana characters in the Japanese code page are not converted.
如字符å 的ASCII编码是229,会被转化成:å 如果在程序中不对其进行HTMLDecode而直接使用(如:string script="window.alert(" + e.Cells[0].Text + ")"; 或是直接保存到数据库中或用其与其他值进行比较等),就会有问题。汉字是不会被HTMLEncode的,在程序中如果不注意这些问题的话,有可能引起系统的错误。
附件是微软提供的一个列表说明了哪些控件的属性会进行HTMLEnocde。
ASPNET Controls HTML Encoding.xlsx (39.12 kb)
by 易水寒
24. July 2009 12:37
越来越多的项目通过自定义Resource Provider来提供多语音支持。一般情况下我们都从实现一个叫ResourceProviderFactory的基类开始,我们要重写其中的两个方法:
public override IResourceProvider CreateGlobalResourceProvider(string classKey) {}
public override IResourceProvider CreateLocalResourceProvider(string virtualPath) {}
其中virtualPath传递的是页面的从根目录开始的页面相对路径,我们将用这个变量去数据库或者XML资源文件中取页面资源。但是为了灵活性,一般情况下资源保存页面路径的时候用的是不包括根目录的相对路径,因此我们需要将virtualPath做一下处理去掉根目录。
考虑到在IIS有两种方式发布ASP.NET程序,一种是使用虚拟目录的方式,我们在开发的过程经常使用这种方式;另一种方式是使用web site的方式,比方说直接把ASP.NET放到Default Web Site下面。在去掉virtualPath的根目录的时候应该充分讨论这两种方式的不同。下面是一个例子:
虚拟目录方式:virtualPath = /ProjectName/module/report/report1.aspx
Default Web Site: virtualPath = /module/report/report1.aspx
我们期待的处理后的virtualPath = module/report/report1.aspx, 它将与资源进行匹配。你有没有在你项目中考虑这两种发布方式呢?检查一下吧。
by jack
14. July 2009 19:34
我在执行.NET应用程序时,遇到如下数据库连接错误:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 0 - No process is on the other end of the pipe.)
错误原因:
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.即:在连接到SQL Server 2005时,错误产生的原因可能是由SQL Server的默认设置不允许远程连接造成的。
解决方法:
确保SQL Server 2005的配置是否正确,允许传入的连接上的实例数据库服务器,否则,使对本地连接和远程连接进行设置。
- Click Start button, then go to Programs or All Programs, then select Microsoft SQL Server 2005 , followed by Configuration Tools .单击开始按钮,然后单击程序按钮,然后选择Microsoft SQL Server 2005项,其次是选择配置工具。 Click and run the SQL Server Surface Area Configuration .点击和运行 SQL Server外围应用配置器,进入界面SQL Server 2005 Surface Area Configuration. On the “SQL Server 2005 Surface Area Configuration” page, click Surface Area Configuration for Services and Connections .
- 单击Surface Area Configuration for Services and Connections On the “SQL Server 2005 Surface Area Configuration” page, click Surface Area Configuration for Services and Connections .On the “Surface Area Configuration for Services and Connections” page, expand Database Engine tree, click Remote Connections .选链接,进入Surface Area Configuration for Services and Connections-localhost界面,在界面左边的树形结构中,先单击MSSQLSERVER结点,再单击其展开的Database Engine结点,单击Remote Connection 项,界面右边将展现出相应的内容。
- 选中Local and remote connections 及其子项Using both TCP/IP and named pipesSelect Local and remote connections , or Local connections only which applicable only if there is no remote system tries to connect to the SQL Server, useful when you just trying to connect and authenticate with the server after installing.
- Click OK button when prompted with the message saying that “Changes to Connection Settings will not take effect until you restart the Database Engine service.”单击OK按钮时,有如下提示讯息:
“Changes to Connection Settings will not take effect until you restart the Database Engine service ”,单击OK按钮,关闭提示,返回到SQL Server 2005 Surface Area Configuration界面 。
- 单击On the “Surface Area Configuration for Services and Connections” page, expand Database Engine tree, click Remote Connections .选择选择Surface Area Configuration for Services and Connections链接,进入Surface Area Configuration for Services and Connections-localhost界面,在界面左边的树形结构中,先单击MSSQLSERVER结点,再单击其展开的Database Engine结点,单击Remote Connection 项,界面右边将展现出相应的内容。
- Click Stop button to stop the SQL Server service.点击 Stop按钮来停止MSSQLSERVER服务。
- Wait until the MSSQLSERVER service stops, and then click Start button to restart the MSSQLSERVER service.MSSQLSERVER服务停止之后,单击Start按钮,重新启动MSSQLSERVER服务。
- 单击OK按钮,退出界面,配置成功。
配置成功之后,问题得到解决!
除此之外,问题还有可能是web.config文件中的数据库连接串中的主机IP或数据库名及服务名错误!!此种情况应特别注意。