<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>eracer.de &#187; ASP.NET</title> <atom:link href="http://www.eracer.de/tag/aspnet/feed/" rel="self" type="application/rss+xml" /><link>http://www.eracer.de</link> <description>ASP.NET, Wordpress, HTML5, jQuery, Javascript, Ajax, Mobile</description> <lastBuildDate>Mon, 16 Jan 2012 08:54:40 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>ASP.NET Calendar: Hide PrevMonthText or NextMonthText</title><link>http://www.eracer.de/asp-net-calendar-hide-prevmonthtext-or-nextmonthtext/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-calendar-hide-prevmonthtext-or-nextmonthtext</link> <comments>http://www.eracer.de/asp-net-calendar-hide-prevmonthtext-or-nextmonthtext/#comments</comments> <pubDate>Sun, 03 Oct 2010 07:37:18 +0000</pubDate> <dc:creator>Stevie</dc:creator> <category><![CDATA[Allgemein]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Calendar]]></category> <category><![CDATA[csharp CalendarControl]]></category><guid
isPermaLink="false">http://www.eracer.de/?p=258</guid> <description><![CDATA[If you use the ASP.NET Calendar Control and want to hide the PrevMonthText or NextMonthText then you need to use the PreRender-Event from the Calendar-Control. In this example I hide the PrevMonthText (Hyperlink) when the current year and month equals calendars visible year and month. Note: You must set/init the VisibileDate-Property in Page_Load-Event. In my [...]]]></description> <content:encoded><![CDATA[<p>If you use the ASP.NET Calendar Control and want to hide the PrevMonthText or NextMonthText then you need to use the PreRender-Event from the Calendar-Control.</p><p>In this example I hide the PrevMonthText (Hyperlink) when the current year and month equals calendars visible year and month. Note: You must set/init the VisibileDate-Property in Page_Load-Event. In my example I want that the start month and year of the control is set to today.</p><div
class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/>8<br
/>9<br
/>10<br
/>11<br
/>12<br
/>13<br
/>14<br
/>15<br
/>16<br
/></div></td><td><div
class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">protected</span> <span
style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span
style="color: #008000;">&#40;</span><span
style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">if</span> <span
style="color: #008000;">&#40;</span><span
style="color: #008000;">!</span>IsPostBack<span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyCalendarControl<span
style="color: #008000;">.</span><span
style="color: #0000FF;">VisibleDate</span> <span
style="color: #008000;">=</span> DateTime<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Now</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">protected</span> <span
style="color: #6666cc; font-weight: bold;">void</span> MyCalendarControl_PreRender<span
style="color: #008000;">&#40;</span><span
style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008080; font-style: italic;">// hide previous month link in calendar when current month and year equals calendars month and year</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyCalendarControl<span
style="color: #008000;">.</span><span
style="color: #0000FF;">PrevMonthText</span> <span
style="color: #008000;">=</span> DateTime<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Now</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Month</span> <span
style="color: #008000;">==</span> EventsCalendar<span
style="color: #008000;">.</span><span
style="color: #0000FF;">VisibleDate</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Month</span> <span
style="color: #008000;">&amp;&amp;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DateTime<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Now</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Year</span> <span
style="color: #008000;">==</span> EventsCalendar<span
style="color: #008000;">.</span><span
style="color: #0000FF;">VisibleDate</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Year</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #008000;">?</span> <span
style="color: #6666cc; font-weight: bold;">string</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Empty</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #008000;">:</span> <span
style="color: #666666;">&quot;&lt;&quot;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div> ]]></content:encoded> <wfw:commentRss>http://www.eracer.de/asp-net-calendar-hide-prevmonthtext-or-nextmonthtext/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ASP.NET AjaxControlToolkit with IE9 Beta</title><link>http://www.eracer.de/asp-net-ajaxcontroltoolkit-with-internet-explorer-9-beta/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-ajaxcontroltoolkit-with-internet-explorer-9-beta</link> <comments>http://www.eracer.de/asp-net-ajaxcontroltoolkit-with-internet-explorer-9-beta/#comments</comments> <pubDate>Thu, 16 Sep 2010 21:01:28 +0000</pubDate> <dc:creator>Stevie</dc:creator> <category><![CDATA[Allgemein]]></category> <category><![CDATA[Ajax]]></category> <category><![CDATA[AjaxControlTookKit]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[IE9]]></category> <category><![CDATA[Internet Explorer]]></category> <category><![CDATA[ToolkitScriptManager]]></category><guid
isPermaLink="false">http://www.eracer.de/?p=224</guid> <description><![CDATA[When I use the ASP.NET AjaxControlToolkit with the ToolkitScriptManager in Internet Explorer 9 Beta I get on every asynchronous postback javascript errormessages like &#8220;Invalid set operation on read-only property&#8221;. Adding this HTML-Metatag 1&#60;meta http-equiv=&#34;X-UA-Compatible&#34; content=&#34;IE=8&#34; /&#62; should fix it. But this is just a workaround not a solution. ASP.NET Forums Thread: http://forums.asp.net/p/1602520/4084902.aspx AjaxControlToolkit Issue-Tracker: http://ajaxcontroltoolkit.codeplex.com/workitem/26832]]></description> <content:encoded><![CDATA[<p>When I use the ASP.NET AjaxControlToolkit with the ToolkitScriptManager in Internet Explorer 9 Beta I get on every asynchronous postback javascript errormessages like &#8220;Invalid set operation on read-only property&#8221;. Adding this HTML-Metatag</p><div
class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #009900;">&lt;<a
href="http://december.com/html/4/element/meta.html"><span
style="color: #000000; font-weight: bold;">meta</span></a> <span
style="color: #000066;">http-equiv</span><span
style="color: #66cc66;">=</span><span
style="color: #ff0000;">&quot;X-UA-Compatible&quot;</span> <span
style="color: #000066;">content</span><span
style="color: #66cc66;">=</span><span
style="color: #ff0000;">&quot;IE=8&quot;</span> <span
style="color: #66cc66;">/</span>&gt;</span></div></td></tr></tbody></table></div><p>should fix it. But this is just a workaround not a solution.</p><p>ASP.NET Forums Thread:</p><p><a
href="http://forums.asp.net/p/1602520/4084902.aspx">http://forums.asp.net/p/1602520/4084902.aspx</a></p><p>AjaxControlToolkit Issue-Tracker:</p><p><a
href="http://ajaxcontroltoolkit.codeplex.com/workitem/26832"> http://ajaxcontroltoolkit.codeplex.com/workitem/26832</a></p> ]]></content:encoded> <wfw:commentRss>http://www.eracer.de/asp-net-ajaxcontroltoolkit-with-internet-explorer-9-beta/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ListView: FindControl im EditItemTemplate</title><link>http://www.eracer.de/listview-findcontrol-im-edititemtemplate/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=listview-findcontrol-im-edititemtemplate</link> <comments>http://www.eracer.de/listview-findcontrol-im-edititemtemplate/#comments</comments> <pubDate>Thu, 24 Jun 2010 19:40:24 +0000</pubDate> <dc:creator>Stevie</dc:creator> <category><![CDATA[Allgemein]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[C-Sharp]]></category> <category><![CDATA[DataItem]]></category> <category><![CDATA[EditItemTemplate]]></category> <category><![CDATA[ItemDataBound]]></category> <category><![CDATA[ListView]]></category> <category><![CDATA[WebForms]]></category><guid
isPermaLink="false">http://www.eracer.de/?p=202</guid> <description><![CDATA[Hier eine einigermaßen vernünftige Lösung um in einem ListView WebControls im EditItemTemplate anzusprechen und Daten vom ListViewDataItem daran zu binden. Ersteres, also das ansprechen der WebControls, ist über den Event &#8220;OnItemEditing&#8221; kein Problem. Hier liegt beim DataItem der Hase im Pfeffer. Bisher habe ich keine Lösung gefunden an das DataItem im &#8220;OnItemEditing&#8221;-Event zu kommen. Der [...]]]></description> <content:encoded><![CDATA[<p>Hier eine einigermaßen vernünftige Lösung um in einem ListView WebControls im EditItemTemplate anzusprechen und Daten vom ListViewDataItem daran zu binden. Ersteres, also das ansprechen der WebControls, ist über den Event &#8220;OnItemEditing&#8221; kein Problem. Hier liegt beim DataItem der Hase im Pfeffer. Bisher habe ich keine Lösung gefunden an das DataItem im &#8220;OnItemEditing&#8221;-Event zu kommen. Der logische Versuch über</p><div
class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var dataItem <span
style="color: #008000;">=</span> MyListView<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Items</span><span
style="color: #008000;">&#91;</span>e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">NewEditIndex</span><span
style="color: #008000;">&#93;</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">DataItem</span><span
style="color: #008000;">;</span></div></td></tr></tbody></table></div><p>an das ListViewDataItem zu kommen schlug fehl, da es immer Null ist.</p><p>Nach langem tüfteln habe ich nun eine gute Lösung gefunden. Im &#8220;ItemDataBound&#8221;-Event wird neben dem ItemType auch der DisplayIndex mit dem EditIndex verglichen. Ist dieser gleich und der EditIndex ist gesetzt (else if-zweig) befinden wir uns EditItemTemplate und können auf die WebControls und das ListViewDataItem zugreifen.</p><p>Beispiel:</p><div
class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/>8<br
/>9<br
/>10<br
/>11<br
/>12<br
/>13<br
/>14<br
/>15<br
/>16<br
/>17<br
/>18<br
/>19<br
/></div></td><td><div
class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">protected</span> <span
style="color: #6666cc; font-weight: bold;">void</span> MyListView_ItemDataBound<span
style="color: #008000;">&#40;</span><span
style="color: #6666cc; font-weight: bold;">object</span> sender, ListViewItemEventArgs e<span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">if</span> <span
style="color: #008000;">&#40;</span>e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Item</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">ItemType</span> <span
style="color: #008000;">==</span> ListViewItemType<span
style="color: #008000;">.</span><span
style="color: #0000FF;">DataItem</span> <span
style="color: #008000;">&amp;&amp;</span> e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Item</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">DisplayIndex</span> <span
style="color: #008000;">!=</span> MyListView<span
style="color: #008000;">.</span><span
style="color: #0000FF;">EditIndex</span><span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #008080; font-style: italic;">//ItemTemplate</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #008080; font-style: italic;">//Hier können ganz normal die WebControls des ItemTemplates per FindControl angesprochen werden. </span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">else</span> <span
style="color: #0600FF; font-weight: bold;">if</span><span
style="color: #008000;">&#40;</span>MyListView<span
style="color: #008000;">.</span><span
style="color: #0000FF;">EditIndex</span> <span
style="color: #008000;">&gt;</span> <span
style="color: #008000;">-</span><span
style="color: #FF0000;">1</span> <span
style="color: #008000;">&amp;&amp;</span> &nbsp;e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Item</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">DisplayIndex</span> <span
style="color: #008000;">==</span> MyListView<span
style="color: #008000;">.</span><span
style="color: #0000FF;">EditIndex</span><span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008080; font-style: italic;">//EditItemTemplate</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var dataItem <span
style="color: #008000;">=</span> <span
style="color: #008000;">&#40;</span>BeispielObject<span
style="color: #008000;">&#41;</span><span
style="color: #008000;">&#40;</span><span
style="color: #008000;">&#40;</span>ListViewDataItem<span
style="color: #008000;">&#41;</span>e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Item</span><span
style="color: #008000;">&#41;</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">DataItem</span><span
style="color: #008000;">;</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var editItemDropDownList <span
style="color: #008000;">=</span> <span
style="color: #008000;">&#40;</span>DropDownList<span
style="color: #008000;">&#41;</span>e<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Item</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">FindControl</span><span
style="color: #008000;">&#40;</span><span
style="color: #666666;">&quot;EditItemDropDownList&quot;</span><span
style="color: #008000;">&#41;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; editItemDropDownList <span
style="color: #008000;">.</span><span
style="color: #0000FF;">DataSource</span> <span
style="color: #008000;">=</span> BusinessLogic<span
style="color: #008000;">.</span><span
style="color: #0000FF;">GetDataSource</span><span
style="color: #008000;">&#40;</span><span
style="color: #008000;">&#41;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; editItemDropDownList <span
style="color: #008000;">.</span><span
style="color: #0000FF;">DataBind</span><span
style="color: #008000;">&#40;</span><span
style="color: #008000;">&#41;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; forumCategorieDropDownList<span
style="color: #008000;">.</span><span
style="color: #0000FF;">SelectedValue</span> <span
style="color: #008000;">=</span> dataItem<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Value</span><span
style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color: #008000;">&#125;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div> ]]></content:encoded> <wfw:commentRss>http://www.eracer.de/listview-findcontrol-im-edititemtemplate/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>[.NET] HttpContext und UnitTests</title><link>http://www.eracer.de/net-httpcontext-und-unittests/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=net-httpcontext-und-unittests</link> <comments>http://www.eracer.de/net-httpcontext-und-unittests/#comments</comments> <pubDate>Tue, 17 Feb 2009 15:24:33 +0000</pubDate> <dc:creator>Stevie</dc:creator> <category><![CDATA[Allgemein]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[HttpContext]]></category> <category><![CDATA[UnitTest]]></category> <category><![CDATA[UnitTesting]]></category> <category><![CDATA[WebServices]]></category><guid
isPermaLink="false">http://www.eracer.de/?p=106</guid> <description><![CDATA[Da ich Unit Testing sehr mag und mehr oder weniger darauf angewiesen bin musste ich vor kurzem ein nerviges Problem lösen was vorallem des öfteren unter ASP.NET WebSites und WebServices auftritt. Verwendet man in einer Methode oder Funktion das Objekt &#8220;HttpContext&#8221; scheitert der UnitTest kläglich bzw. kann nicht weiter ausgeführt werden da in der UnitTest-Umgebung [...]]]></description> <content:encoded><![CDATA[<p>Da ich Unit Testing sehr mag und mehr oder weniger darauf angewiesen bin musste ich vor kurzem ein nerviges Problem lösen was vorallem des öfteren unter ASP.NET WebSites und WebServices auftritt. Verwendet man in einer Methode oder Funktion das Objekt &#8220;HttpContext&#8221; scheitert der UnitTest kläglich bzw. kann nicht weiter ausgeführt werden da in der UnitTest-Umgebung der HttpConext den Wert &#8220;null&#8221; hat. Nach ein wenig Googeln habe ich mir eine annehmbare Lösung gestrickt. Man simuliert einen HttpContext im Konstruktor der Testklasse und gaukelt somit der zu testenten Applikation einen HttpContext vor.</p><p>Hier das Code-Beispiel dafür, funktioniert bei mir einwandfrei. Der Inhalt der Variablen ist dabei relativ egal.</p><div
class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/>8<br
/>9<br
/>10<br
/>11<br
/>12<br
/>13<br
/>14<br
/></div></td><td><div
class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span
style="color: #0600FF; font-weight: bold;">public</span> <span
style="color: #6666cc; font-weight: bold;">class</span> IrgendwasTest<br
/> &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span> &nbsp; &nbsp; &nbsp;<br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0600FF; font-weight: bold;">public</span> IrgendwasTest<span
style="color: #008000;">&#40;</span><span
style="color: #008000;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #6666cc; font-weight: bold;">string</span> appVirtualDir <span
style="color: #008000;">=</span> <span
style="color: #666666;">&quot;/&quot;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #6666cc; font-weight: bold;">string</span> appPhysicalDir <span
style="color: #008000;">=</span> <span
style="color: #666666;">@&quot;C:\Users\&quot;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #6666cc; font-weight: bold;">string</span> page <span
style="color: #008000;">=</span> <span
style="color: #666666;">@&quot;localhost&quot;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #6666cc; font-weight: bold;">string</span> query <span
style="color: #008000;">=</span> <span
style="color: #6666cc; font-weight: bold;">string</span><span
style="color: #008000;">.</span><span
style="color: #0000FF;">Empty</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextWriter output <span
style="color: #008000;">=</span> <span
style="color: #0600FF; font-weight: bold;">null</span><span
style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SimpleWorkerRequest workerRequest <span
style="color: #008000;">=</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
style="color: #008000;">new</span></a> SimpleWorkerRequest<span
style="color: #008000;">&#40;</span>appVirtualDir, appPhysicalDir, page, query, output<span
style="color: #008000;">&#41;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext context <span
style="color: #008000;">=</span> <a
href="http://www.google.com/search?q=new+msdn.microsoft.com"><span
style="color: #008000;">new</span></a> HttpContext<span
style="color: #008000;">&#40;</span>workerRequest<span
style="color: #008000;">&#41;</span><span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext<span
style="color: #008000;">.</span><span
style="color: #0000FF;">Current</span> <span
style="color: #008000;">=</span> context<span
style="color: #008000;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #008000;">&#125;</span><br
/> <span
style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div> ]]></content:encoded> <wfw:commentRss>http://www.eracer.de/net-httpcontext-und-unittests/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 9/29 queries in 0.008 seconds using disk: basic
Object Caching 728/778 objects using disk: basic

Served from: www.eracer.de @ 2012-02-05 17:43:05 -->
