2008年3月26日 星期三

asp.net viewstat decoder

http://www.pluralsight.com/tools.aspx

ViewState Decoder (2.2)

Fritz OnionTool to decode the ViewState in ASP.NET 2.0 pages. This version supports display of control state as well as view state. Screenshot

ViewState Decoder (1.1)

Fritz OnionTool to decode the ViewState in ASP.NET pages compatible with version 1.1 of ASP.NET Screenshot

http://blogs.msdn.com/rextang/archive/2007/05/25/2868250.aspx

2008年3月20日 星期四

asp.net forms authentication Web.Config 範例

如果某一個aspx網頁不需要驗證就可以存取,可以在web.config 加上Location 這個標籤

<configuration>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
</forms>
<
/authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
<authorization>
<deny users="?" />
</authorization>
<
/system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
<location path="default1.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
<
/system.web>
</location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder. -->
<location path="subdir1">
<system.web>
<authorization>
<allow users ="*"
/>
</authorization>
<
/system.web>
</location>
<
/configuration>

2008年2月25日 星期一

如何在 client 端 動態修改 Custom Validator 的 error message

有User的需求是希望能用alert的方式顯示出 validator 的 錯誤訊息, Validation Summary 有一個「ShowMessageBox」property 剛好可以提供這樣的功能,但是如果你的Page上有包含 Custom Validator , 而 Custom Validator的錯誤訊息會依據不同的條件顯示的話,如何在 client 動態修改 Custom Validator 的 error message呢?

重點就是要修改 Custom Validator Client script 的 sender dom 物件,說明如下:

function fn_myValidator(sender, args)
{
sender.innerHTML = "錯誤:" + new Date().toLocaleString();
sender.errormessage = "錯誤:" + new Date().toLocaleString();
args.IsValid = false;
}

ASP.net 會將 Custom Validator render 成一個 DOM object,其中的 errormessage 屬性就是validation summary control 顯示時會去讀的資料,因此只要在Custom Validator Client script改變這個值,validation summary就會Show 出新的 error message,但是如果你希望改變Custom Validator 本身顯示在 網頁上的 error message , 就需要修改 Custom Validator 的 innerHTML or innerText。

可以參考以下兩串討論

2008年2月4日 星期一

消失的IIS ASP.NET Tab(頁籤)

在Windows 2003 Server 上的 IIS ASP.NET Tab , 有時會莫名的失蹤,解決方法如下
http://jamesmckay.net/2008/01/missing-aspnet-tab-in-iis-on-windows-server-2003/
  1. Stop IIS using iisreset /stop
  2. Open the file C:\WINDOWS\system32\inetsrv\MetaBase.xml in Notepad.
  3. Find and delete the line that says Enable32BitAppOnWin64="TRUE"
  4. Restart IIS using iisreset /start
  5. If you still don’t see your ASP.NET tab, aspnet_regiis -i should now work.
另外也可以用

ASP.NET Version Switcher


來取代

2007年12月11日 星期二

使用 TableAdapter 時,如何取得 stored procedure 的 return value

Visual Studio 2005的 TableAdapter ,不會回傳 stored procedure 的 return value,解決方法之一是寫一個 partial class ,然後從 CommandCollection 的 Parameters 取得 stored procedure 的 return value ,可以參考:
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx

namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}


範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。

2007年11月15日 星期四

.Net 2.0 內建的 Hex byte array converter

在 System.Runtime.Remoting.Metadata.W3cXsd2001 命名空間內 , 有.Net 2.0 內建的 Hex byte array converter:SoapHexBinary 可以作 Hex string anf byte array 之間的轉換,
http://msdn2.microsoft.com/zh-tw/library/system.runtime.remoting.metadata.w3cxsd2001.soaphexbinary_members(VS.80).aspx

2007年11月6日 星期二

讀取自然人憑證內的身分證字號後4碼

自然人憑證內的身分證字號後4碼,存放於OID=2.5.29.9 這個 extension 內,如果要用 windows 的 crypto api 讀取的話,要用到以下的 API
PCERT_EXTENSION WINAPI CertFindExtension(
__in LPCSTR pszObjId,
__in DWORD cExtensions,
__in CERT_EXTENSION rgExtensions[]
);

範例如下:
PCERT_EXTENSION pCert_extension;

pCert_extension=CertFindExtension(szOID_SUBJECT_DIR_ATTRS,pInfo->cExtension,pInfo->rgExtension);
char szID[5];
if (pCert_extension!=NULL){
// 身分證字號後4碼在這個擴充欄位的最後面
memcpy(szID,(char *)(pCert_extension->Value.pbData)+(pCert_extension->Value.cbData-4),4);
szID[4]=0;
printf("ID:%s\n",szID);
}