人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 30, 2006

webcast_How do I Video Series_Localization

Filed under: ASP.NET

How do I? Video Series : Localization (hilo_localization_final.wmv)
http://asp.net/default.aspx?tabindex=4&tabid=3000
http://asp.net/learn/howdoi/default.aspx?tabid=63

0. Resource 语法
显式: <%$ Resources:[filename prefix,]resource-key %>

隐式: <asp:Label ID=”Label1″ runat=”server” meta:resourcekey=”resource-key-prefix” />

1. 使用Local resource

可以使用菜单Tools->Generate Local Resource来生成local resource.
foo.aspx will refer to the /App_LocalResources/foo.aspx.resx

Create a special folder named “App_LocalResources”.
Create a resource file named “Default.aspx.resx” in it.
Create a resource file named “Default.aspx.fr.resx” in it.

3. Using the resource in the control
<asp:Button ID=”Button1″ runat=”server” Text=”Button” meta:resourceKey=”Button1″/>

4. Set culture for the page
<%@Page … UICulture=”auto”>

在IE中可以设置 default language,从而进行测试

5. 使用Global resource
所有的page, user-control都可以访问
Create a special folder named “App_GlobalResources”.
Create a resource file named “Resource.resx” in it.
Create a resource file named “Resource.fr.resx” in it.

6. 设置Control.Expressions 属性
Sample1:
Bindable properties 设为 Text
Expression Type 设为 Resource
Expression properties 的ClassKey 设为 Resource
Expression properties 的ResourceKey 设为 “资源名称”
Sample2:
Bindable properties 设为 BackColor
Expression Type 设为 Resource
Expression properties 的ClassKey 设为 Resource
Expression properties 的ResourceKey 设为 “资源名称”

7. 通过代码设置Culture

using System.Threading;
using System.Globalization;

protected override InitializeCulture()
{
string lang = Resuest(” “);

Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
Thread.CurrentThread.CurrentCulture = new CultureInfo.CreateSpecificCulture(lang);
}

参考

ASP.NET 2.0 Localization Features: A Fresh Approach to Localizing Web Applications

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/asp2local.asp

ZBlogWriter

Filed under: Blog使用

发现了一个很好用的blog writer.

http://www.zoundry.cn/download.html

它可以把blog备份到本地C:\Program Files\Zoundry Blog Writer\users\**\docrepo

可以编辑已发布的blog的分类及内容(注意 check “update existing post”)

按分类发表blog

写很多再一次性post

第一次使用时,出现了异常,但重新打开,已写的内容还存在.

XP自动安装

Filed under: 使用技巧

1.在安装盘 SUPPORT 目录的 Tools 子目录中,找到一个名为 Deploy 的 CAB 压缩文件,将该文件解压即可看到 setupmgr.exe 程序
  运行之,可生成自动安装应答文件unattend.txt.
   
2.以从光盘安装为例:

   (1)在纯 DOS 下用 format A:/s 命令格式化一张软盘。

  (2)把unattend.txt 拷进软盘里

  (3)在软盘里创建文件 Autoexec.bat,并编辑命令行:
        set AnswerFile=unattend.txt
        set SetupFiles=CDDriver:\I386
        %SetupFiles%\winnt32 /s:%SetupFiles% /u:%AnswerFile% /t:C:
     (4)把软盘和光盘一同放进机器里, 启动顺序设置软盘,光盘引导。

注: 核心就是传给winnt32的两个参数: /s /u

SQL2005中xp_cmdshell安全性增强

Filed under: SQL&DB Accessing

在程序中用到以下的机制来新建一个account 库
1 datach account 标准库,
2 copy account 标准库的mdf文件,生成新的account库mdf文件.
3 attach 新的account库.

但是这个过程的步骤2会在sql2005上出错.
可用以下的sql语句来重现这个错误

1 create database AA
2 exec sp_detach_db AA,’True’
3 exec xp_cmdshell ‘copy /Y "c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\AA.mdf" "D:\AA.mdf"’

语句1执行后会生成一个AA.mdf文件,在查看其属性中的Sercurity页,会看到以下帐号
Administrator
Network service
Service

sql2000中当语句2执行后查看AA.mdf文件属性中的Sercurity页,会看到以下帐号
Administrator
SQLServer2005MSSQLUser$机器名$实例名
Service

而在sql2005中当语句2执行后查看AA.mdf文件属性中的Sercurity页,只会看到当前操作者的帐号

语句3中的xp_cmdshell是以Service权限执行的,所以在Sql2005下会失败.
提示Access is denined.

同时,如果sqlserver中已经禁止掉xp_cmdshell的使用,会看到以下的错误提示:
SQL Server blocked access to procedure ’sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this
component is turned off as part of the security configuration for this server.
A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure.
For more information about enabling ‘xp_cmdshell’, see "Surface Area Configuration" in SQL Server Books Online.

 

附:
http://msdn2.microsoft.com/zh-cn/library/ms190693(SQL.90).aspx

sql2005默认情况下,xp_cmdshell 安装时处于禁用状态,但是可以通过使用
外围应用配置器工具(Configuration Tools->SQL Server Surface Area Configuration)
或运行 sp_configure 系统存储过程来启用它,代码如下:

– To allow advanced options to be changed.
EXEC sp_configure ’show advanced options’, 1
GO
– To update the currently configured value for advanced options.
RECONFIGURE
GO
– To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
GO
– To update the currently configured value for this feature.
RECONFIGURE
GO

ASP.NET Event Validation

Filed under: ASP.NET

引用
ASP.NET Event Validation and "Invalid Callback Or Postback Argument"
http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx
http://odetocode.com/Blogs/scott/archive/2006/03/21/3153.aspx

参照
Please, please, please, learn about injection attacks!
http://weblogs.asp.net/bleroy/archive/2004/08/18/216861.aspx

ASP.net 添加了"event validation"的功能, ASP.NET会检查 POST方法中的所带的参数,如果
认为不合法,就会抛出异常,信息如下

    Invalid postback or callback argument.
        Event validation is enabled using <pages enableEventValidation="true"/> in
    configuration or <%@ Page EnableEventValidation="true" %> in a page. 
        For security purposes, this feature verifies that arguments to postback or
    callback events originate from the server control that originally rendered them. 
        If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
    method in order to register the postback or callback data for validation.
   
这个设计的目的是为了防止恶意用户利用post 方法发送一些恶意数据.但是有时一些常见的
case也会出错,比如使用客户端脚本,根据页面上的其他控件的内容来改变一个dropdown list的内容,最常见的case
就是省市县3级联动菜单.又比如在页面上添加一个dropdown list,然后给它添加3个item,再使用客户端脚本在
dropdown list中添加一个item,如果dropdown list的AutoPostBack="True",每次选择list item都会引起postback,
如果所选的item为dropdown list本来就有的,一切正常.如果所选的item是通过客户端脚本添加的,就会出现异常.

在asp.net render DropDownList 时,会遍历DropDownList的item,并记录所有可能的postback的值,其算法为
hash(DropDownList’s UniqueID XOR hash(ListItem’s Value property)),计算的结果会被保存在page中,

<input type="hidden"
       name="__EVENTVALIDATION"
       id="__EVENTVALIDATION"
       value="/wEWBQKGg9abDQKd9sHMBgKc9s…….."
/>
这个过程发生在control的Render()方法中
当页面postback时,ASP.NET会根据这个隐藏值检查postback values,如果找不到对应信息,就会报错

结局方案
1. 禁止这个功能, 但同时会失去一些安全保障:
//—-通过web.config
<system.web>
   <pages enableEventValidation="false"/>
</system.web>
//—-针对某个page
<%@ Page EnableEventValidation="false" … %>

2.Register For Event Validation
其原理就是让asp.net记录这个postback value.
RegisterForEventValidation必须在render时调用.

protected override void Render(HtmlTextWriter writer)
{
   ClientScript.RegisterForEventValidation(_recipeList.UniqueID,"4");
   base.Render(writer);
}

如果我们自己写了一个control,需要使用validate events功能,就需要使用SupportsEventValidation attribute,

[SupportsEventValidation]
public class DynamicDropDownList : DropDownList
{
  protected override void Render(System.Web.UI.HtmlTextWriter writer)
  {
     Page.ClientScript.RegisterForEventValidation(this.UniqueID, "4");
     base.Render(writer);
  }
}

目前,asp.net还不能单独禁止某个control的validate events功能.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham