<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>LA.NET [EN] : ASP.NET</title><link>http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx</link><description>Tags: ASP.NET</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Enabling session state programmatically</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/12/11/enabling-session-state-programmatically.aspx</link><pubDate>Fri, 11 Dec 2009 15:18:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744859</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1744859</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/12/11/enabling-session-state-programmatically.aspx#comments</comments><description>&lt;p&gt;“Finally!!!”, you say…I hear you man! With ASP.NET 4.0, we can enable/disable session state programmatically (like in C# code :) ). The new version of the framework adds a new method (SetSessionStateBehavior) to the HttpContext class. You’re supposed to pass it a value from the SessionStatebehavior to influence the use of session state. Currently, you can pass the following values:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Default: passing this means that everything works as before (ie, you control session through the @page directive or the &amp;lt;pages&amp;gt; entry in the web.config file);&lt;/li&gt;    &lt;li&gt;Required: session state is enabled for read/write access;&lt;/li&gt;    &lt;li&gt;ReadOnly: gives access to read only session state;&lt;/li&gt;    &lt;li&gt;Disabled: turns off session state for the current request.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In practice, passing one of the last three methods means that eventual settings specified at the @Page directive or in the &amp;lt;pages&amp;gt; element of the config file are ignored. There’s a caveat: you can only use the new method influence the use of state until the AcquireRequestState event is fired. Doing it after means getting an exception.&lt;/p&gt;  &lt;p&gt;And that’s it. Stay tuned for more on ASP.NET.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744859" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Another cool nudge: maintaining the selection of an element when using paging</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/12/10/another-cool-nudge-maintaining-the-selection-of-an-element-when-using-paging.aspx</link><pubDate>Thu, 10 Dec 2009 10:24:42 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744617</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1744617</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/12/10/another-cool-nudge-maintaining-the-selection-of-an-element-when-using-paging.aspx#comments</comments><description>&lt;p&gt;This is one of those simple things which really improves the use of controls like GridView and ListView. ASP.NET 4.0 adds the EnablePersistedSelection property to the GridView and ListView controls. To support this feature, the control ended up adding a new field (_persistedDataKey) which is saved in the control state of the control. Notice that what is persisted is the key that uniquely identifies the selected item (and not its position in the rows displayed by the grid.&lt;/p&gt;  &lt;p&gt;When the grid needs to create its rows, it will update the SelectedIndex (and other associated props) by checking the data key of each item it is rendering against the value persisted in the _persisteDataKey field. What this means is that when you change the page and go to a new one that doesn’t have the previous selected item, you’ll end up getting –1 for the SelectedIndex property. I guess this isn’t really the behavior you’d expect, but I’m assuming that it wasn’t changed so that it was backward compatible with previous versions (or it might end up breaking existing code). To recover the current selected item you’ll have to use the new SelectedPersistedKey property (which returns a DataKey object associated with the item that has been selected).&lt;/p&gt;  &lt;p&gt;And that’s it for now. Keep tuned for more&amp;#160; on ASP.NET.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744617" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Ensuring that IIS 7 will handle extensionless URLs</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/12/09/ensuring-that-iis-7-will-handle-extensionless-urls.aspx</link><pubDate>Wed, 09 Dec 2009 14:55:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744423</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1744423</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/12/09/ensuring-that-iis-7-will-handle-extensionless-urls.aspx#comments</comments><description>&lt;p&gt;As you probably know, I’ve been updating my ASP.NET book to 4.0. It has been more work that initially expected, but I can also say that I’ve been having some fun. One of the things I’ve had to investigate was routing. This is one of those cool additions that will really help improve SEO in web forms apps (ASP.NET had some support for friendly URLs, but it was close to useless :)) &lt;/p&gt;  &lt;p&gt;Now, if you’ve been doing MVC, you already know that routes are an important feature and you probably know lots about it (btw, I’ve written &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2008/07/04/the-routing-series.aspx"&gt;about it&lt;/a&gt; in the past). One of the things you probably know is that getting extensionless URLs in IIS 6 involves some configuration. However, that shouldn’t be needed in IIS 7 and above. I guess it was a surprise to me when I started getting 404 on my demo app for routing in Web Forms. What? 404? But I’m running the site in IIS 7 with integrated mode on…wtf??? &lt;/p&gt;  &lt;p&gt;Well, after some tweaking, I’ve managed to understand what was going on: you must ensure that the routing module is configured to handle managed and unmanaged requests (there are several options for doing this; the easiest is using the IIS 7 admin console – check the properties of a module and you should see a dialog with a checkbox that lets you enable/disable this feature). &lt;/p&gt;  &lt;p&gt;I’ve started asking around and I was lucky enough to get an answer from &lt;a href="http://www.amazon.com/Professional-ASP-NET-Security-Membership-Management/dp/0764596985"&gt;Stefan S&lt;font color="#acacac"&gt;c&lt;/font&gt;hackow&lt;/a&gt; about it. When you create a new VS project, you’ll see that the web.config contains the following entry:&lt;/p&gt;  &lt;pre style="background-color:black;" class="code"&gt;&lt;span style="color:#a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;modules &lt;/span&gt;&lt;span style="color:#009b00;"&gt;runAllManagedModulesForAllRequests&lt;/span&gt;&lt;span style="color:#a1b070;"&gt;=&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#44b1e3;"&gt;true&lt;/span&gt;&lt;span style="color:#d6d694;"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color:#a1b070;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;this is all that takes to make everything run smoothly. Unfortunately, I’ve ended up deleting that entry from the web.config and that meant that my extensionless URL never got through the URL module (it ended up being processed by the static file handler, which is not a managed handler). Special thanks go to &lt;a href="http://www.amazon.com/Professional-ASP-NET-Security-Membership-Management/dp/0764596985"&gt;Stefan&lt;/a&gt; for helping me with this problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744423" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>The “Cannot open user default database…” error</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/12/05/the-cannot-open-user-default-database-error.aspx</link><pubDate>Sat, 05 Dec 2009 11:34:32 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1743774</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1743774</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/12/05/the-cannot-open-user-default-database-error.aspx#comments</comments><description>&lt;p&gt;Today I’ve ended up getting the following error after refreshing a page that was working (3 minutes before):&lt;/p&gt;  &lt;h3&gt;Server Error in &amp;#39;/&amp;#39; Application.    &lt;hr /&gt;&lt;/h3&gt;  &lt;h4&gt;&lt;i&gt;Cannot open user default database. Login failed.     &lt;br /&gt;Login failed for user &amp;#39;IIS APPPOOL\ASP.NET v4.0&amp;#39;.&lt;/i&gt;&lt;/h4&gt; &lt;b&gt;Description: &lt;/b&gt;An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  &lt;br /&gt;&lt;b&gt;Exception Details: &lt;/b&gt;System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.  &lt;br /&gt;Login failed for user &amp;#39;IIS APPPOOL\ASP.NET v4.0&amp;#39;.  &lt;p&gt;As I said, this happened while I was updating the code for my book and it happened when I hit refresh on a working page in the browser. So, if it was working just a few minutes ago, why did it stopped working? It must have been something I’ve done, but what? After some seconds, I’ve remembered that I did add a new LINQ To SQL file to my project and that it used the same SQL Express database (user instance) than the remaining site. After checking the Server Explorer, I could see that VS was still connected to the instance database. And yes, that was the problem: closing the connection on Server Explorer made the error go away!&lt;/p&gt;  &lt;p&gt;I’m almost positive that this was not the error one got in previous versions of ASP.NET (when an user instance was opened by some other process), but I might be wrong. Now, the important thing is that if you end up getting this error, you should check if there’s anything holding up your user instance db file. And that’s it. Stay tuned for more.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1743774" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>The new ViewState model</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/12/03/the-new-viewstate-model.aspx</link><pubDate>Thu, 03 Dec 2009 21:18:55 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1743536</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1743536</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/12/03/the-new-viewstate-model.aspx#comments</comments><description>&lt;p&gt;Everybody knows that using view state means that you’ll go to hell when you die….nonetheless, many keeps using it, even after having been warned about it (probably because they find heaven to dull??? who knows :) )…to be honest, the default opt-out model we had until now didn’t really helped. The good news is that ASP.NET 4.0 introduces a new model known as opt-in model. So, what’s the idea behind it? A quick recap of what we had is in order…until 4.0, view state was controlled through the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx"&gt;EnableViewState&lt;/a&gt; property. Whenever you set it to false, you’re saying that that control and all its children won’t persist any data in view state. &lt;/p&gt;  &lt;p&gt;Now, this caused all sorts of quirks in v1.0 because programmers would turned it off at the page level (less KBs in a page is good, right?) and all hell broke loose because server controls stopped working. The workaround was simple: leave it on by default at the page level and turn it off in all the controls that don’t need it (btw, this was called the opt-out model). Even though ASP.NET 2.0 introduced control state to make controls work without relying on view state, the truth is that existing opt-out view state model still sucked in the real world because 1.) people are lazy and/or 2.) there was always someone who ended up forgetting to disable view state in the controls they’ve added to the page.&lt;/p&gt;  &lt;p&gt;Now, things are better with ASP.NET 4.0 and its new opt-in model. In order to make it work, they’ve added a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode(VS.100).aspx"&gt;ViewStateMode&lt;/a&gt; property, which gets its value from an enum with the same name.Currently, it supports the these values:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Inherit: inherits the value of the property from its control parent. This is the default value;&lt;/li&gt;    &lt;li&gt;Enabled: enables view state in the current control (even if the parent has its ViewStateMode set to Disabled);&lt;/li&gt;    &lt;li&gt;Disabled: disables view state in the current control.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Before going, you must understand that this property will only be of use when the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx"&gt;EnableViewState&lt;/a&gt; property is set to true (when it’s set to false, view state is off for that control and all the controls on its control tree). Now, lets see how we can use this new property and the new opt-in model. &lt;/p&gt;  &lt;p&gt;By default, &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode(VS.100).aspx"&gt;ViewStateMode&lt;/a&gt; is set to inherit (default value inherited from the Control class itself – which, btw, also sets &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx"&gt;EnableViewState&lt;/a&gt; to true). Now, if you set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode(VS.100).aspx"&gt;ViewStateMode&lt;/a&gt; at page level to Disabled, you can turn it on only for the controls that need it by setting that property to enabled on those controls. This is the new (and let me add this: cool!) opt-in model introduced by ASP.NET 4.0.&lt;/p&gt;  &lt;p&gt;Final note: If you debug an ASP.NET page, you’ll notice that Inherits is still the value of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode(VS.100).aspx"&gt;ViewStateMode&lt;/a&gt; property…if that is the case, then view state shouldn’t be on by default, right? After all, Page is the top control in the control tree and the docs clearly say that view state is on only when the ViewState is set to Enabled or when a parent control has that value and the current one has its mode set to Inherits…so, “what gives?” (reaped shamelessly from &lt;a href="http://www.imdb.com/title/tt0756573/"&gt;October Road&lt;/a&gt;, another great TV show which ended abruptly…it seems like these ABC guys terminate all the series I like…oh, lets leave this whining to a future post) &lt;/p&gt;  &lt;p&gt;The answer lies on the private SaveAllState method, which is responsible for persisting view state info into the hidden field (the default behavior). When it sees that the ViewStateMode of the page is set to Inherits, it will automatically use Enabled instead. And that’s it. I’ll try to come back with more on ASP.NET.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1743536" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Getting 503 errors on IIS 7 with custom application pool (Integrated Mode)?</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/26/getting-503-errors-on-iis-7-with-custom-application-pool-integrated-mode.aspx</link><pubDate>Thu, 26 Nov 2009 15:23:06 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1742291</guid><dc:creator>luisabreu</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1742291</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/26/getting-503-errors-on-iis-7-with-custom-application-pool-integrated-mode.aspx#comments</comments><description>&lt;p&gt;So today I’ve though about giving IIS’ integrated mode a shot…The idea was simple: create a new application pool, configure it to use ASP.NET 4.0 in integrated mode and then associated it to an existing web application. The problem: The first request would always kill the application pool and it returned a 503 error to the browser. IIS Manager seemed to confirm that the pool was really dead:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/5241.wrongversion_5F00_51B0F2D7.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="wrongversion" border="0" alt="wrongversion" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/luisabreu.metablogapi/3175.wrongversion_5F00_thumb_5F00_0DAD0EC0.png" width="439" height="332" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;WTF? I’ve read a couple of posts on IIS 7 and 503, but none helped. Then I tried one more thing: I’ve configured the web app to use the default ASP.NET v4.0 application pool. And it worked…the mystery was solved when I looked carefully at the application pool list. Can you spot the problem? If you’re thinking that my custom livro application pool is using the wrong .NET version, you’re right! I don’t know how it happened, but it seems like all this beta stuff I’ve been adding to my machine removed the correct version of .NET from the .NET version dropdown (I only had v4.0 available from the dropdown list). &lt;/p&gt;  &lt;p&gt;Running aspnet_iisreg from within the 4.0 framework folder made everything go back to normal. So, are you getting 503 in integrated mode? Don’t forget to check the .NET version used by the application pool…it might not exist and that means 503!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1742291" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Changing the action attribute of an HtmlForm</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/26/changing-the-action-attribute-of-an-htmlform.aspx</link><pubDate>Thu, 26 Nov 2009 12:29:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1742276</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1742276</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/26/changing-the-action-attribute-of-an-htmlform.aspx#comments</comments><description>&lt;p&gt;In these last days I’ve went back to ASP.NET world (server side) since I’m thinking in rewriting my ASP.NET &lt;a href="http://www.fca.pt/cgi-bin/fca_main.cgi/?isbn=978-972-722-615-3&amp;amp;op=2"&gt;book&lt;/a&gt; (which was written way back when ASP.NET 2.0 was released and which got a slight updated for .NET 3.5). One of the&amp;#160; things I’ve noticed is that now we can change the action attribute of a form and it sticks! According to my &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.action.aspx"&gt;investigations&lt;/a&gt;, this behavior was changed with the release of .NET 3.5.&lt;/p&gt;  &lt;p&gt;Now, you might be thinking on why you’d want to use this attribute…it’s specially cool when you’re using friendly urls (remember: in the past, we didn’t had any url routing engines). Suppose you’re using the old friendly urls introduced by ASP.NET 2.0:&lt;/p&gt;  &lt;p&gt;&amp;lt;add url=&amp;quot;~/Activities&amp;quot; mappedUrl=&amp;quot;~/Activities.aspx&amp;quot;/&amp;gt;&lt;/p&gt;  &lt;p&gt;Now, the problem with pre-3.5 releases was that you couldn’t set the Action property and you’d end up getting the Activites.aspx in your browser’s location box. There were some hacks, but….they were simply hacks…With the 3.5 behavior change, those hacks can finally go back into the garbage bin! hurray! :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1742276" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Asking feedback for ASP.NET book</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/24/asking-feedback-for-asp-net-book.aspx</link><pubDate>Tue, 24 Nov 2009 12:35:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1741958</guid><dc:creator>luisabreu</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1741958</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/24/asking-feedback-for-asp-net-book.aspx#comments</comments><description>&lt;p&gt;This is a post to my Portuguese readers (ie, for those guys and gals that have read my Portuguese books). I’m still preparing material for a possible ASP.NET 4.0 book and I would really appreciate some feedback on the previous editions (that is, if you read the book). What did you like? What didn’t you like? What would you like to see covered? &lt;/p&gt;  &lt;p&gt;If you want, you can put your comments in Portuguese. Thanks for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1741958" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Books/default.aspx">Books</category></item><item><title>Crash dumps, ASP.NET and VS 2010</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/11/06/crash-dumps-asp-net-and-vs-2010.aspx</link><pubDate>Fri, 06 Nov 2009 22:21:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1738108</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1738108</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/11/06/crash-dumps-asp-net-and-vs-2010.aspx#comments</comments><description>&lt;p&gt;Pretty cool &lt;a href="http://feedproxy.google.com/~r/ScottHanselman/~3/NM-VgzLgdWo/HanselminutesOn9DebuggingCrashDumpsWithTessFerrandezAndVS2010.aspx"&gt;stuff&lt;/a&gt;!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738108" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Rick’s tip on ASP.NET client IDs + JQuery</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/10/15/rick-s-tip-on-asp-net-client-ids-jquery.aspx</link><pubDate>Thu, 15 Oct 2009 13:55:08 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1732556</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1732556</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/10/15/rick-s-tip-on-asp-net-client-ids-jquery.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://west-wind.com/weblog/"&gt;Rick Strahl&lt;/a&gt; has an interesting &lt;a href="http://feedproxy.google.com/~r/RickStrahl/~3/x5Lv96f1OnE/42319.aspx"&gt;post&lt;/a&gt; on how you might use &lt;a href="http://jquery.com/"&gt;JQuery’s&lt;/a&gt; powerful selector syntax to get a reference to an ASP.NET control placed inside a naming container. Pretty cool stuff :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1732556" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/Javascript/default.aspx">Javascript</category></item><item><title>Dave Reed on MS AJAX 4 preview 5</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/09/13/dave-reed-on-ms-ajax-4-preview-5.aspx</link><pubDate>Sun, 13 Sep 2009 21:43:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1723090</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1723090</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/09/13/dave-reed-on-ms-ajax-4-preview-5.aspx#comments</comments><description>&lt;p&gt;Another excellent &lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2009/09/11/microsoft-ajax-4-preview-5-the-dataview-control.aspx"&gt;post&lt;/a&gt; by &lt;a href="http://weblogs.asp.net/infinitiesloop/"&gt;Dave Reed&lt;/a&gt; on a topic which I shall begin looking at in depth next week.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1723090" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MS+AJAX/default.aspx">MS AJAX</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Has ASP.NET really left the track?</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/08/24/has-asp-net-really-left-the-track.aspx</link><pubDate>Mon, 24 Aug 2009 11:12:28 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1717857</guid><dc:creator>luisabreu</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1717857</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/08/24/has-asp-net-really-left-the-track.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/hpreishuber/default.aspx"&gt;Hannes Preishuber&lt;/a&gt; has a post which asks if &lt;a href="http://weblogs.asp.net/hpreishuber/archive/2009/08/22/asp-net-have-left-the-track.aspx"&gt;ASP.NET has left the track&lt;/a&gt;? It seems like &lt;a href="http://weblogs.asp.net/hpreishuber/default.aspx"&gt;Hannes&lt;/a&gt; is bashing the team for not improving the platform since the 2.0 release. I agree with this idea, though not with the specifics. In fact, in all the web apps I’ve worked until now, I’ve only used a couple of ASP.NET server controls. I’ve found most of them useless since I’ve ended up needing much more control over the generated HTML.&lt;/p&gt;  &lt;p&gt;In fact, I’m not sure if I’d want the team to waste more time with ineffective controls. I’d really prefer that they would update the core infrastructure instead. For instance, my friend &lt;a href="http://www.paulomorgado.net/"&gt;Paulo&lt;/a&gt; has already made several useful &lt;a href="http://connect.microsoft.com/SearchResultsLive.aspx?SearchQuery=paulo%2bmorgado"&gt;suggestions on connect&lt;/a&gt; which are way more important than getting more controls…&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1717857" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>MVC Action filter project on Codeplex</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/28/mvc-action-filter-project-on-codeplex.aspx</link><pubDate>Tue, 28 Apr 2009 09:46:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1691458</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1691458</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/28/mvc-action-filter-project-on-codeplex.aspx#comments</comments><description>&lt;p&gt;Roni Schuetz informed me of a new &lt;a href="http://www.codeplex.com"&gt;Codeplex&lt;/a&gt; project he created for building a &lt;a href="http://mvcactionfilter.codeplex.com/"&gt;common library&lt;/a&gt; of ASP.NET MVC action filters. If you’re into MVC and you’d like to contribute, then &lt;a href="http://mvcactionfilter.codeplex.com/"&gt;check it out&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1691458" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: the ActionLink control</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/13/the-mvc-framework-the-actionlink-control.aspx</link><pubDate>Mon, 13 Apr 2009 20:43:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1687281</guid><dc:creator>luisabreu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1687281</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/13/the-mvc-framework-the-actionlink-control.aspx#comments</comments><description>&lt;p&gt;Ok, so today I’ve finally updated my local copy of the MVC source code (which I’m doing through my preferred SVN client) and lo-and-behold: new stuff to talk about in the MVC futures source code! Today we’re going to talk about the ActionLink control. &lt;/p&gt;  &lt;p&gt;As you might expect (from the name), this is a really simple control which extends the base MvcControl. Currently, it exposes the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;ActionName: lets you pass the action name that should be used for rendering the link;&lt;/li&gt;    &lt;li&gt;ControllerName: lets you set the name of the controller. Used for influencing the generated url;&lt;/li&gt;    &lt;li&gt;RouteName: as you’ve probably guessed, you can use this to generate a link by using its name;&lt;/li&gt;    &lt;li&gt;Values: lets you pass a dictionary for setting the route’s dictionary values;&lt;/li&gt;    &lt;li&gt;Text: used for setting the text that is generated for the link.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt; If you’re used to using the &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/01/29/the-mvc-framework-working-with-anchors.aspx"&gt;Html.ActionLink helper&lt;/a&gt;, then there really shouldn’t be anything new in here. Anyway, here’s an example of how you can use this new control in your page:&lt;/p&gt;  &lt;p&gt;&amp;lt;mvc:actionlink runat=&amp;quot;server&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ActionName=&amp;quot;About&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Text=&amp;quot;Go to about&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;Unlike the other controls, the name property isn’t really used internally to get any info from the view data dictionary. You’re probably wondering how you can fill the Values property. Nothing better than a quick example…the next snippet creates a link to the Index action and sets its id property (I’m using the default routes you get when you create a new MVC app):&lt;/p&gt;  &lt;p&gt;&amp;lt;mvc:actionlink runat=&amp;quot;server&amp;quot; ActionName=&amp;quot;Index&amp;quot; Text=&amp;quot;Go to about&amp;quot; name=&amp;quot;message&amp;quot;&amp;gt;   &lt;br /&gt;&amp;#160; &amp;lt;Values id=&amp;quot;1&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;lt;/mvc:actionlink&amp;gt;&lt;/p&gt;  &lt;p&gt;This ends up generating the following HTML:&lt;/p&gt;  &lt;p&gt;&amp;lt;a name=&amp;quot;message&amp;quot; href=&amp;quot;/MvcRTM/home/Index/1&amp;quot;&amp;gt;Go to about&amp;lt;/a&amp;gt;&lt;/p&gt;  &lt;p&gt;If you had more parameters, you could simply add them as attributes to the Value element. And that’s it for today. Stay tuned for more on the MVC framework.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1687281" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: the AcceptAjaxAttribute</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/09/the-mvc-framework-the-acceptajaxattribute.aspx</link><pubDate>Wed, 08 Apr 2009 23:01:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1686060</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1686060</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/09/the-mvc-framework-the-acceptajaxattribute.aspx#comments</comments><description>&lt;p&gt;There might be some scenarios where you have methods that should only be invoked for AJAX requests. In those cases, you can use the AcceptAjaxAttribute to decorate those methods. This is an ActionMethodSelectorAttribute which overrides the IsValidForRequest and delegates all its work to the Request.IsAjaxRequest extension method. &lt;/p&gt;  &lt;p&gt;When you’re not in an AJAX request, the IsAjaxRequest method returns false and you end up getting a 404 for that call. It’s really a simple attribute and you might want to &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/02/04/the-mvc-platform-interacting-with-the-actionmethodselectorattributes.aspx"&gt;recall&lt;/a&gt; how ActionMethodSelectorAttributes interact with the remaining elements of the platform.&lt;/p&gt;  &lt;p&gt;And that’s all there is to say about this attribute. Stay tuned for more on the MVC framework.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1686060" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: setting a timeout</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/07/the-mvc-framework-setting-a-timeout.aspx</link><pubDate>Tue, 07 Apr 2009 20:58:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1685678</guid><dc:creator>luisabreu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1685678</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/07/the-mvc-framework-setting-a-timeout.aspx#comments</comments><description>&lt;p&gt;In the last posts, we’ve taken a look at how we can add asynchronous action to a controller. Today, we’re going to dig a little deeper and see how we can specify a timeout that limits the maximum amount of time that the asynchronous operations can take to complete.&lt;/p&gt;  &lt;p&gt;By default, you inherit a default timeout: all actions must complete under 30 seconds (as you can see, if you peek into the AsyncManager class). You can specify the timeout in two ways: by interacting directly with the AsyncManager’s Timeout property or by using one of the existing timeout attributes.&lt;/p&gt;  &lt;p&gt;If you want to use an attribute, then you can simply decorate a method (or a controller class) with the AsyncTimeoutAttribute. This is an action filter attribute which receives an integer that defines the valid timeout for the current asynchronous request. If you don’t want to limit the asynchronously execution in time, then you can simply pass Timeout.Infinite(–1) to the constructor. Alternatively, you can also annotate the method/controller with the NoAsyncTimeoutAttribute (this attribute expands the previous one and passes Timeout.Infinite to its constructor).&lt;/p&gt;  &lt;p&gt;And that’s all for today. Keep tuned for more on the MVC framework.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1685678" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: the RequireSslAttribute</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/06/the-mvc-framework-the-requiresslattribute.aspx</link><pubDate>Mon, 06 Apr 2009 21:00:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1685298</guid><dc:creator>luisabreu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1685298</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/06/the-mvc-framework-the-requiresslattribute.aspx#comments</comments><description>&lt;p&gt;The RequireSslAttribute is a filter attribute which you can apply to a class or method and which is responsible for overriding the OnAuthorization method and seeing if the current request is being done over SSL. The filter exposes a single property, called Redirect. &lt;/p&gt;  &lt;p&gt;When it detects that the current request is not under SSL, it checks the Redirect property: if it’s set to true, then it will build an https url based on the current request and redirect the user to that new url; if the Redirect property is set to false, then it will simply throw an exception.&lt;/p&gt;  &lt;p&gt;And that’s all there is to know about this attribute. Keep tuned for more on the MVC framework.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1685298" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: the “delegate” pattern for asynchronous actions</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-delegate-pattern-for-asynchronous-actions.aspx</link><pubDate>Sun, 05 Apr 2009 21:13:44 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684957</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1684957</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-delegate-pattern-for-asynchronous-actions.aspx#comments</comments><description>&lt;p&gt;This is the last post in the asynchronous action pattern series. In this post, we’re going to present the (so called) “delegate” pattern. This is really similar to the “event” pattern. The difference is that, in this case, we return a parameterless delegate from our begin method which will be called when all the asynchronous operations end. &lt;/p&gt;  &lt;p&gt;To illustrate this pattern, we’re going to update the &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-simplifying-the-event-pattern.aspx"&gt;previous example&lt;/a&gt;. Here’s the final code:&lt;/p&gt;  &lt;p&gt;public Func&amp;lt;ActionResult&amp;gt; GetHtml(String url) {   &lt;br /&gt;&amp;#160; var req = WebRequest.Create(url);    &lt;br /&gt;&amp;#160; req.Method = &amp;quot;GET&amp;quot;;    &lt;br /&gt;&amp;#160; AsyncManager.RegisterTask(cb =&amp;gt; req.BeginGetResponse(cb, null),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ar =&amp;gt; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var response = req.EndGetResponse(ar);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; using (var reader =     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new StreamReader(response.GetResponseStream())) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ViewData[&amp;quot;contents&amp;quot;] = reader.ReadToEnd();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ); &lt;/p&gt;  &lt;p&gt; return () =&amp;gt; View(“Index”);   &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;When compared with the “event” pattern, you can quickly see that:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;the begin method returns a parameterless delegate which will be called when all the asynchronous operations end;&lt;/li&gt;    &lt;li&gt;since we can’t pass any parameters to our custom callback method, we write the HTML directly to the ViewData dictionary;&lt;/li&gt;    &lt;li&gt;we use a Lambda expression since the view we’re rendering doesn’t have the same name as the action method (if that was the case, we could simply return a reference to the View method, ie, we could simply write return View;).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And that’s all for today. More about the MVC framework on the next posts. Keep tuned!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684957" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: simplifying the “event” pattern</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-simplifying-the-event-pattern.aspx</link><pubDate>Sun, 05 Apr 2009 21:01:49 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684955</guid><dc:creator>luisabreu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1684955</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-simplifying-the-event-pattern.aspx#comments</comments><description>&lt;p&gt;In the &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-event-pattern.aspx"&gt;previous post&lt;/a&gt;, we’ve taken a look at the “event” pattern. In this post, we’re going to see how we can simplify the needed code for using this pattern. The AsyncManager exposes a RegisterTask method which simplifies the needed code when we decide to use this pattern. We’ll improve the previous example by using this method. Here’s the code:&lt;/p&gt;  &lt;p&gt;public void GetHtml(String url) {   &lt;br /&gt;&amp;#160; var req = WebRequest.Create(url);    &lt;br /&gt;&amp;#160; req.Method = &amp;quot;GET&amp;quot;;&amp;#160; &lt;br /&gt;&amp;#160; AsyncManager.RegisterTask(cb =&amp;gt; req.BeginGetResponse(cb, null),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ar =&amp;gt; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var response = req.EndGetResponse(ar);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; using (var reader =     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new StreamReader(response.GetResponseStream())) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AsyncManager.Parameters[&amp;quot;contents&amp;quot;] = reader.ReadToEnd();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ); &lt;/p&gt;  &lt;p&gt;} &lt;/p&gt;  &lt;p&gt;public ActionResult GetHtmlCompleted(String contents) {   &lt;br /&gt;&amp;#160; ViewData[&amp;quot;contents&amp;quot;] = contents;    &lt;br /&gt;&amp;#160; return View(&amp;quot;Index&amp;quot;);    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;As you can see, the code is really similar to the &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-event-pattern.aspx"&gt;one&lt;/a&gt; we’ve shown in the other post. The main difference is that with this helper method you’ll only need to worry with setting up the asynchronous action.&lt;/p&gt;  &lt;p&gt;And that’s all for today. On the next post, we’ll talk about the latest option for having asynchronous actions in MVC controllers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684955" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item><item><title>The MVC framework: the “event” pattern</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-event-pattern.aspx</link><pubDate>Sun, 05 Apr 2009 20:37:41 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684953</guid><dc:creator>luisabreu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/luisabreu/rsscomments.aspx?PostID=1684953</wfw:commentRss><comments>http://msmvps.com/blogs/luisabreu/archive/2009/04/05/the-mvc-framework-the-event-pattern.aspx#comments</comments><description>&lt;p&gt;Today we’re going to keep looking at the MVC framework and we’ll see how we can use the “event” pattern for invoking an action asynchronously. This pattern is really simple. You start by adding two methods: the first is responsible for kicking off the asynchronous processing and the second will be called when all the asynchronous actions complete (as you’ll see, with this approach you can start several asynchronous actions). The ending method’s name should follow a specific convention: it must end with the word Completed (where XXX is the name of the action method that is exposed by your controller) and it should return the ActionResult object responsible for kicking off the view rendering phase. &lt;/p&gt;  &lt;p&gt;When you opt for this approach, you’ll have to notify the framework whenever you start an asynchronous task (and you also need to signal its end). In practice, this means that you’ll have to increment the AsyncManager’s OutsandingOperations property whenever you start an asynchronous action. And then you’ll also have to decrement this property when that async operation is completes. Internally, this property delegates to a counter and when that counter reaches 0, the platform will automatically invoke your XXXCompleted method.&lt;/p&gt;  &lt;p&gt;Your XXXCompleted method might also receive parameters that are automatically fed with the values that might have been added to the AsyncManager’s Parameters property. In practice, when the platform invokes the XXXCompleted method, it will try to match the expected XXXCompleted parameters with values that might exists on the AsyncManager’s Parameters property. Those parameters which don’t exist in that Parameters property get their default value (default(T)).&lt;/p&gt;  &lt;p&gt;The restrictions presented for the &lt;a href="http://msmvps.com/blogs/luisabreu/archive/2009/04/02/the-mvc-framework-the-iasyncresult-pattern.aspx"&gt;IAsyncResult pattern&lt;/a&gt; applies to this option too. That means that filters must be applied to the begin method (and not to the end method) and that the end method must match the real method name (instead of an eventual alias name that might have been applied to that method). Enough theory…it’s time to show some code. We’re going to reuse the previous example and change it so that we apply this pattern:&lt;/p&gt;  &lt;p&gt;public void GetHtml(String url) {   &lt;br /&gt;&amp;#160; var req = WebRequest.Create(url);    &lt;br /&gt;&amp;#160; req.Method = &amp;quot;GET&amp;quot;;    &lt;br /&gt;&amp;#160; AsyncManager.OutstandingOperations.Increment();&amp;#160; &lt;br /&gt;&amp;#160; req.BeginGetResponse(    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (ar) =&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var response = req.EndGetResponse(ar);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; using (var reader = new StreamReader(response.GetResponseStream())) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AsyncManager.Parameters[&amp;quot;contents&amp;quot;] = reader.ReadToEnd();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AsyncManager.OutstandingOperations.Decrement();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; },    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; null);    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;public ActionResult GetHtmlCompleted(String contents) {   &lt;br /&gt;&amp;#160; ViewData[&amp;quot;contents&amp;quot;] = contents;    &lt;br /&gt;&amp;#160; return View(&amp;quot;Index&amp;quot;);    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;There are a couple of interesting observations that you can take from this example:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;we increment the OustandingOperations before kicking the asynchronous operation;&lt;/li&gt;    &lt;li&gt;at the end of the callback method, we decrement the OutstandingOperations. When it reaches 0, the GetHtmlCompleted method is called;&lt;/li&gt;    &lt;li&gt;notice that we use the Parameters property to set the contents parameter value. btw, if we wanted we could also add an entry to the ViewData dictionary instead of doing that in the XXXCompleted method.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Even though the sample has only kicked off one asynchronous operation, nothing prevents you from starting several asynchronous operations. The only thing you can’t forget to do is to keep track of the current running asynchronous operations by incrementing and decrementing the OutstandingOperations property.&lt;/p&gt;  &lt;p&gt;And that’s it for today. More about asynchronous &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684953" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/luisabreu/archive/tags/MVC/default.aspx">MVC</category></item></channel></rss>