2009年11月15日日曜日

[IIS6.0] Webガーデン

IIS6.0導入されたWebガーデンについてのメモです。

Webガーデンで最大ワーカープロセス数を2以上にした場合に注意が必要。
Webガーデンとは、1つのアプリケーションを複数のワーカープロセスで動かす仕組み。
アプリケーション変数や、セッションは共有されない。
つまり、SessionIdは別物になる。
Session領域も別物になる。
システム構築時にクラスタ構成と同じように考慮する必要がある。

あんな簡単に設定できるものが、こんなに大きく影響があってよいのですかねぇ。

2009年11月11日水曜日

[ASP.NET MVC] リストのモデルバインド

ASP.NET MVCでモデルバインドが便利っぽいような不便っぽいような。
新規にリストの値をバインドするなら問題ないのですよ。

Model

Public Class PrivateInfo
Public Name As String
Public History As List(Of History)
End Class

Public Class History
Public eventDate As DateTime
Public Score As Int32
Public Cost As Int32
End Class


View

<%
For each item In Model.History
Dim index As Integer = Model.History.IndexOf(item)
%>
<%=Html.TextBox(String.Format("History[{0}].Score", index), item.Score)%>
<%=Html.TextBox(String.Format("History[{0}].Cost", index), item.Cost)%>

<% Next%>


ところがですね、すでにある程度の値が入っているリストに画面でeventDateを設定させようとしてUpdateModelすると、ScoreとCostが消えちゃうのです。
View

<%
For each item In Model.History
Dim index As Integer = Model.History.IndexOf(item)
%>
<%=Html.TextBox(String.Format("History[{0}].eventDate", index), item.eventDate)%>

<% Next%>


Controller

<AcceptVerbs(HttpVerbs.Post)> _
Public Function Input2(ByVal collection As FormCollection) As ActionResult
Dim model As Models.PrivateInfo = Session("PrivateInfo")

UpdateModel(model)

Return View(model)
End Function



そこまでやってくれないんですね。
対策としては、その他の項目もPostしちゃうと。

View

<%
For each item In Model.History
Dim index As Integer = Model.History.IndexOf(item)
%>
<%=Html.TextBox(String.Format("History[{0}].eventDate", index), item.eventDate)%>
<%=Html.Hidden(String.Format("History[{0}].Score", index), item.Score)%>
<%=Html.Hidden(String.Format("History[{0}].Cost", index), item.Cost)%>

<% Next%>



イケテナイ。
自分でマージするか