2007年3月29日 星期四

網頁中有部份不要Cache

in aspx <% Response.WriteSubstitution(new HttpResponseSubstitutionCallback(CallbackFunction)); %> 或者直接拉一個 Substitution control,並設定其 MethodName 為 CallbackFunction in code behind protected static string CallbackFunction(HttpContext context){ return DateTime.Now.ToString("HH:mm:ss");}

2007年3月28日 星期三

打開 database 的 service broker

alter database Northwind set enable_broker

使用 DEVPATH 找出組件

之前,一直沒有注意到這個小細節。 一旦要開發,就一頭往Vs2005 裡頭鑽。 開發人員可能會想要確定他們正在建置的共用組件是否會與多個應用程式一起正確工作。不需在開發循環一再將組件置於全域組件快取,開發人員可代之以建立 DEVPATH 環境變數來指向組件的組建輸出目錄。 例如,假設您正在建置 (Build) 稱為 MySharedAssembly 的共用組件,而輸出目錄為 C:\MySharedAssembly\Debug。您可以將 C:\MySharedAssembly\Debug 放在 DEVPATH 變數中。您必須接著在電腦組態檔中指定 項目。這個項目會告訴 Common Language Runtime 要使用 DEVPATH 來找出組件。 下列範例顯示如何使 Runtime 在 DEVPATH 環境變數所指定的目錄中搜尋組件。 這個設定值預設為 false。 注意 只可在開發時間使用這個設定值。Runtime 不會檢查在 DEVPATH 中所找到的強式名稱組件版本。它只使用它所找到的第一個版本。

應該要換電腦了

我公司配給我的IBM R50 notebook,真的不行了。 如果只是用來打打字,收收email,上上網,游刃有餘。 但是,我最常做的事,卻是RSS,Visual Studio 2005,測試SQL Server 2005,WCF,WPF,WF, 及眾多的application block,也測試過Vista。 R50、40Gb HDD, 768MB Memory 哪夠? 強迫,一定要換 Desktop PC。不要NoteBook 也行。 NoteBook 自己家裡已經有了。拿來Demo 時,只要能遠端連線即可。

2007年3月27日 星期二

在已經存在的 Web Site, 使用WCSF

請參考 http://blogs.msdn.com/mpuleio/archive/2007/03/25/using-the-wcsf-with-existing-web-site-projects.aspx 。 這對於要「升級」網站的開發方式,有極大的幫助。

2007年3月22日 星期四

FckEditor 也有 asp.net 2.0 的assembly

請參考 http://wiki.fckeditor.net/Developer%27s_Guide/Integration/ASP.Net, 這裡也有web control 可以拖拉到 web form 上哦。 真是方便

http://ajunlee.pbwiki.com/Fckeditor安裝說明

http://ajunlee.pbwiki.com/Fckeditor安裝說明 一直以來,都有線上html 編輯器的需要。 這是一個良好的編輯器。

2007年3月21日 星期三

GridView 中欄位顯示 DataTime 的問題

在GridView 中,要顯示 DataTime時,會出現如 4/21/2005 12:00:00 AM 的格式 設定 DataFormatString 為 {0:d} 也是沒有用。 這時要設定該 Bound Filed 之 HtmlEncode = false; HtmlEncode 預設為 true, 用來對付不安全的 script,可是在 format string 上卻意外造成 issue。 我想這應該是 asp.net 2.0 的design issue。

WCSF 中所使用的Enterprise Library 版本

WCSF 中所使用的Enterprise Library 版本,是使用位在 C:\Program Files\Microsoft Web Client Factory\Microsoft Practices Library 中的 assemblies, 但於January 2006 的版本,卻是 2.0.0.0 的,造成了 version 不相容。 只好全部指向新版的folder。

2007年3月20日 星期二

BPEL for Windows Workflow Foundation March CTP

BPEL for Windows Workflow Foundation March CTP

可於此處下載

http://www.microsoft.com/downloads/details.aspx?familyid=6d0daf00-f689-4e61-88e6-cbe6f668e6a3&displaylang=en

老闆一直要我看 BPEL 相關的東西,終於有進入點了

2007年3月16日 星期五

於asp.net 上存取 msmq 的權限問題

最近寫了一個小程式,用來demo 在實作 soa時, 應該如何設計 web service。 所以需要以 wcf 來存取 msmq 我使用了 local computer 的 private queue 但當 wcf service 存取 msmq 時,卻發生權限的問題。 我在 wcf service 之 web.config 上,加上了具有管理權限的設定 也是不能動。(於 xp sp2 上開發) 解決方法如下:
  1. 使用 Windows 2003 的 application pool: 設該application pool 之identity
  2. xp sp2: 在msmq 之管理 snap-in上,將該 queue 之安全性,設定 computerName\aspnet 為full control (好像太多了)

後來就解決了.

2007年3月15日 星期四

AddressAlreadyInUseException

 

使用WCF ,且使用wsDualHttpBinding , 常常Client app 會發生如下的錯誤

 

System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL http://+:80/Temporary_Listen_Addresses/c030eb34-4c63-446f-b4d1-0bb7df8c4774/ because TCP port 80 is being used by another application. ---> System.Net.HttpListenerException: 程序無法存取檔案,因為檔案正由另一個程序使用。

 

這是因為 wsDualHttpBinding 預設也是使用 80 port,而此 port 已被 IIS 的預設網站使用了。

 

此時,必須在 client app.conifg 設定 clientBaseAddress 為不同的 port

 

<wsDualHttpBinding>

                <binding clientBaseAddress=http://localhost:9865/myClient/ />

Microsoft Office Word、Excel 及 PowerPoint 2007 檔案格式相容性套件

是否有收到 Office 2007 所產生的文件,如 docx, xlsx, pptx?而使用 office 2003 的您,是否無法打開此類文件。

這時您可以試著安裝相容套件。

Microsoft Office WordExcel PowerPoint 2007 檔案格式相容性套件

將物件序列化到 xml 字串

常看到的範例是將物件序列化到檔案。

但最常需要的卻是序列化到字串。

 

請參考以下範例。注意要 PlaceOrderRequest 必須是Serializable

 

private string GetXmlContent(PlaceOrderRequest request)

    {

      StringWriter writer = new StringWriter();

      XmlSerializer xs = new XmlSerializer(typeof(PlaceOrderRequest));

      xs.Serialize(writer, request);

      return writer.ToString();

    }

LINQ 的方法

今天看了 LINQ 的Demo 原來我之前寫的 ORM tool 早已不實用了。 微軟在 C# 3.0 加入了 LINQ,將 ORM 實作於語言層級,使的ORM 的工具更上一層樓。 然而使用者卻看不出來有 ORM 的外貌。 因此,LINQ 可以達到資料庫查詢,object (in memory) 的查詢,更進一步可達到 資料庫與 memory object 的 inner join 查詢。 硬是要得。

2007年3月13日 星期二

[HowTo]整合Visual Studio 2005與Service Pack 1

參考來源為 [HowTo]整合Visual Studio 2005與Service Pack 1 這傢伙實在是太強了,他的blog 是VS.NET 開發人員應該常看的。

2007年3月12日 星期一

Web Service Software Factory

這個東西很好用。真沒想到微軟愈來愈smart 了。 不過,要按照順序安裝以下的東西。連結到 google 找一下就有了。 Enterprise Library for .NET Framework 2.0 - January 2006 GuidanceAutomationExtensions.msi GuidanceAutomationToolkit.msi Web Service Software Factory - December 2006 (refresh).msi 要試試哦!真是好東西。

Microsoft SQL Server 2005 Service Pack 2 又出來了

Microsoft SQL Server 2005 Service Pack 2 又出來了!!

2005/11/07 2007/03/06短短的14個月,出了SQL Server 2005, sp1, sp2

實在不知道應該罵還是應該讚賞。

有需要者,請到 http://www.microsoft.com/downloads/details.aspx?familyid=D07219B2-1E23-49C8-8F0C-63FA18F26D3A&amp;mg_id=10111&displaylang=en 下載

Visual Studio 2005 Service Pack 1 版本資訊

Visual Studio 2005 Service Pack 1 版本資訊

2007年3月6日 星期二

Service Design Golden Rule

1 10X 設計。當需求為100 concurrent user時,設計一個 1000 concurrent users 的系統。

Enterprise system 中,Client 與 Server 的比例

今天看到的,忍不住寫了下來。

在典型的 Enterprise system中,current client 的比例為 1%,高負載的也才3%

換句話說,當設計一個 current user 100 user 的系統時,其實際的 user 10000 人。

 

微軟 ASP.NET 2.0 AJAX Extensions 1.0 Source Code

微軟在 Ajax 上的努力,已經有正式版出來了。

        而且,竟然公佈了 source code!!

        微軟真的是愈來愈 open mind .

        願意研究的,請自行下載。       

ASP.NET 2.0 AJAX Extensions 1.0 Source Code

 

The request for security token has invalid or malformed elements

在更新 WCF Server Side config 之後,執行 Client Side app 後,在client side app 出現了下列一段的錯誤訊息

 

System.ServiceModel.FaultException: The request for security token has invalid or malformed elements.
   at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)
   at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)

 

覺得莫明其妙。後來才驚覺,在Client Side config 尚未更新。導致Server Side 要求以 A 方式驗證,而Client Side 仍以 B 驗證方式提出Request

 

當然會被當成 malformed element 了。

 

vs2005 update service reference ,更新 config 後即ok

 

安裝 LINQ CTP(May 2006) 後再移除,VS2005 Refactoring 功能不見了

安裝完 Microsoft Visual Studio Code Name "Orcas" - LINQ CTP (May 2006) ,再移除後,發現 VS2005 IDE Refactoring 功能不見了。

這真的很不方便。試了重新設定環境,依然沒效。

 

最後,上了 google ,找到了方法。

 

1. Start up RegEdit.exe

2. Open registry key [HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\8.0\Packages\{A066E284-DCAB-11D2-B551-00C04F68D4DB}\SatelliteDLL]

3. Edit the "Path" value and change it from "C:\Program Files\Microsoft Visual Studio 8\VC#\VCSPackages\1033\" to "C:\Program Files\Microsoft Visual Studio 8\VC#\VCSPackages\"

4. Go to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

5. Run Devenv.exe /Setup

6. Run Devenv.exe /ResetUserData

7. Run Devenv.exe /ResetSettings CSharp

 

Using CasPol to Fully Trust a Share

這是從網路上找來的。來源已記不清楚。

當我想部署VSTO 時,security 一直是很麻煩的事。指令一直記不清楚。

Using CasPol to Fully Trust a Share

Since network shares by default only get LocalIntranet permissions, it's relatively common to want to use CasPol to fully trust some shares that you control and know are safe.  However, CasPol syntax being what it is, the command to do this isn't immediately obvious.  If I wanted to trust everything on the share \\ShawnFa-Srv\Tools, the command:

CasPol.exe -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust

Would setup the policy to do what I needed.  Lets break down this command:

·         -m  - modify the machine level of the policy.  This is needed, since the machine level is where all of the default policy lives.  On NT platforms it's also the default level that CasPol works with, however on Win9x, CasPol will default to the user level, so putting -m in the command line explicitly tells CasPol to use the correct level.

·         -ag 1.2  - add a code group under group 1.2.  In the default policy, group 1.2 is the LocalIntranet group, so the new code group that we're creating will only be checked if the file comes from the intranet.

·         -url file://ShawnFa-Srv/Tools/*  - The membership condition for the new code group should be a UrlMembershipCondition, and it should match anything with a URL that starts with file://ShawnFa-Srv/Tools, meaning that any file on the \\ShawnFa-Srv\Tools share will match this code group.

·         FullTrust  - The permission set to grant assemblies that match the code group.  In this case, FullTrust.

Once you know the pattern, it's pretty easy to modify this command line to do slightly different things.  For instance, if I want to trust only a specific non-strongly named assembly on my share, I might use

CasPol -m -ag 1.2 -hash SHA1 -file \\ShawnFa-Srv\Tools\CodeCSS\CodeCSS.exe FullTrust

Which will create a hash membership condition that matches the SHA1 hash of the CodeCSS.exe file.

When I install a new build of the runtime, my install script actually ends with two lines that do just this:

CasPol.exe -pp off -m -ag 1.2 -url file://ShawnFa-Srv/Tools/* FullTrust
copy config\security.config config\security.config.default

Which trusts everything coming off of a share on my computer, and then makes a copy of that policy as the new default, so that all future calls to CasPol -all -reset do not remove this modification.

 

%windir%\Microsoft.NET\Framework\v2.0.50727\caspol -m -ag LocalIntranet_Zone -url "\\SampleSharePointServer\vstodocs\*" FullTrust -n "VSTO Documents"

%windir%\Microsoft.NET\Framework\v2.0.50727\caspol -m -ag LocalIntranet_Zone -url "http://SampleSharePointServer/sitedirectory/*" FullTrust -n "VSTO SharePoint Documents"

 

Virtual PC 2007

        Virtual PC 2007 又來了。

        仍是免費的。微軟出的。自己看簡介

        產品在測試時,特別好用。

 

WCF 的 Asp.Net MemberShipAndRoleProvider sample



一直想試試看 WCF internet 上如何做到 message security 的功能


試了MemberShipAndRoleProvider 這一個 sample


是可以執行的。


但我自己寫了一個來試,卻又一直試不出來。


發生錯誤The X.509 certificate CN=localhost chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. 撤銷功能無法檢查憑證的撤銷


在比對之下,才發現一個事實。


MemberShipAndRoleProvider sample 下,有個假設,是已執行伺服器端的憑證。但該CA卻不存在。因此,無法達到 Chain trust的功能。


因此,必須將 Client side ChainTrust 改成PeerOrChainTrust。而在Client Side Trusted Person 加入該網站的憑證。


因為該 client side 信任該網站的憑證,且certificateVericationMode 設成 PeerOrChainTrust,就會確認是不是受信任的人。是的話,就成功了。


<behaviors>


<endpointBehaviors>


<behavior name="ClientEndPointBehavior">


<clientCredentials>


<serviceCertificate>


<authentication certificateValidationMode="PeerOrChainTrust" />


</serviceCertificate>


</clientCredentials>


</behavior>


</endpointBehaviors>


</behaviors>


WinInet 限制每個伺服器連線

使用 IE 下載同一個網站的資料,同時只能下載兩個。

這真的是很不合理。

 

可以到 http://support.microsoft.com/kb/183110 這裡,看看要如何動手腳。

 

使用svcutil 製作非同步之 client proxy code

當已製作非同步的 wcf Service code 完成後,皆下來,就是要製作 client proxy code

 

但使用 Visual Studio 2005 with WCF extension 後,卻無法製作出非同步的 client code BeginXXX, EndXXX

 

後來才發現,在這一版,尚未支援製作非同步的 client proxy code。必需自行使用 svcutil.exe 製作

 

試了好久,終於

 

svcutil http://localhost/BankproPortal/Security.svc /a /ct:System.Collections.Generic.List`1 /namespace:*,UABClient.localhost

/mergeConfig  /config:app.config

 

必須注意到

·         `1是必須的,而且是鍵盤左上方的`,而不是單引號的 '

·         /namespace 的語法,我不知道為何必須是這樣,但這樣的確可以

參考自 http://www.dasblonde.net/CommentView,guid,c132e497-7fdb-4895-9b71-8542d0400d52.aspx 

svcutil /d:d:\LearningWCF /noconfig /o:serviceproxy.cs /r:ContentTypes.dll /ct:System.Collections.Generic.List`1 http://localhost:8000

 

Visual Studio 2005 已出到 SP1

Visual Studio 2005 已出到 SP1,請參考Visual Studio 2005 SP1

不過好玩的是,仍然無法支援 Vista

 

Updater Application Block 與 ClickOnce

最近要研究並使用「自動更新」的功能。

 

我發現,ClickOnce 真的很好用,開發非常簡單,也很實用。但是卻只能是 Per-User ,不能是 all user

換句話說,每一個人都必須要自己安裝過一次

 

Updater Application Block 卻沒有這個問題。但目前正式的版本只有for .net framework 1.1

後來發現了 V2.0 版,而且是for .net framework 2.0

 

看來符合我的需求了。

 

IConfigurationSectionHandler 與 ConfigurationSection

以前自訂 config 檔時,常常遇到一個問題,就是必須實作IConfigurationSectionHandler,用來讀取 config file 中的一個 section

接著,又必須寫一個 data class ,並將 config handler 中讀取到的資料填到 data class 中。

如果 config 中的資料是階層式的呢?例如定義一個上傳類型,需要幾個檔案。每個檔案的檔名格式,檔的目錄。

這樣的話,就必須寫多個 data class

 

.net framework 2.0 中,就可以用 ConfigurationSection 來對應了。

而且非常自然,讀取上也方常方便。

 

 

VS 2005 Html Design View 超慢改善方法

不知道大家是否覺得,使用 VS 2005 開發 Web site 變的超慢!

找了一下網路資源,發現可能是 Navigation bar 的問題。

請在 Tools / Options / Text Editor /Html 中,找到 Display Navigation bar check box 清除掉。

我試了一下,果然快很多。

[2007/03/14]

目前VS2005 已經出到了SP1,已對此問題做出了修正。

HTML Source Editing Performance Improvements in VS 2005 SP1

To add "Atlas" features to an ASP.NET application:

1.  Open the ASP.NET application in Visual Studio.

2.  Copy the "Atlas" run-time assembly (Microsoft.Web.Atlas.dll) from its installation folder to the application's Bin folder. By default, the "Atlas" assembly is installed in this location:

C:\Program Files\Microsoft ASP.NET\Atlas\v2.0.50727\Atlas

3.  Open the Web.config file in the "Atlas" default location.

4.  Copy elements required for "Atlas" to the Web.config file in your application's root folder.

Copy these elements as children of the <configuration> element:

  <configSections>

    <sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">

      <section name="converters" type="Microsoft.Web.Configuration.ConvertersSection"/>

    </sectionGroup>

  </configSections>

 

  <microsoft.web>

    <converters>

      <add type="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>

      <add type="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>

      <add type="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>

    </converters>

  </microsoft.web>

Copy (or integrate) these elements as children of the <system.web> element:

    <pages>

      <controls>

        <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>

        <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>

      </controls>

    </pages>

 

    <!-- ASMX is mapped to a new handler so that proxy javascripts can also be served. -->

    <httpHandlers>

      <remove verb="*" path="*.asmx"/>

      <add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>

    </httpHandlers>

    <httpModules>

      <add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>

    </httpModules>

5.  Close all files.

 

SOA 系統的四大特性

每次都會忘記。因此記在這裡。

1.  明確的系統邊界

2.  自主性服務

3.  服務之間分享資料綱要(Schema)與合約(Contract)而非程式類別(class)

4.  服務相容性由原則決定

 

Atlas 使用 DragOverlayExtender 會重回原始位置問題

我開始使用 Atlas 了。不錯用。

 

有個問題,使用 DragOverlayExtender 時,將物件 drag html 的底部時,常常會回到原來的位置。

 

爬了一下文,這有解的。

 

請在 html body 上增加 style="height:100%" 即可。

 

也使用 FormView extend dragable, 但是在切換模式(Edit, Insert) 或換頁時,還是會跑回原位置。不知解麼解?

 

目錄名稱不正確

VS2005 開發 WebSite 時,如果改一個 control id 出現了錯誤 "目錄名稱不正確"

請參考 http://www.dotnet-news.com/lien.aspx?ID=20417

 

dotnet 2.0 的送信 API

.net 2.0 時,送信的 api 已經正式與 System.Web 分開了

程式碼如下

 using System.Net.Mail;

 

MailAddress toAddress = new MailAddress(To);
      MailAddress fromAddress = new MailAddress(From);
      MailAddressCollection msgCollection = new MailAddressCollection();
      msgCollection.Add(toAddress);

      MailMessage message = new MailMessage(fromAddress, toAddress);

      SmtpClient smtp = new SmtpClient("srkm");
      smtp.UseDefaultCredentials = true;
      //smtp.UseDefaultCredentials = false;
      //smtp.Credentials = new System.Net.NetworkCredential("bankpro\\charles", "password");
      //smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
      smtp.Send(message);

 

發信時,可以使用 authenticate 的帳號,密碼。(使用 NetworkCredential)

 

如果要用登入 windows 的帳號,則只需將 UseDefaultCredentials 設為 true 即可 (如範例)

 

有一點需注意。如果有裝 Symantec Client Security,則使用 default credential 發信大概會失敗。此時需裝

Internet e-mail auto protect 模組關閉,才會正常。

 

這可能是 Symantec 攔截到 mail,掃毒完後,無法再以 default credential 發信的,因此會失敗。

如果指定了帳號/密碼,則才會成功。

 

這對程式撰寫來說,真是麻煩。

 

Share with Facebook