Thoughts from Dan Miser RSS 2.0
# Sunday, January 16, 2011
I'm running a web site with MSSQL 2008R2 Express as the backend. Unfortunately, that means there are some enterprise features missing. Most notably, a way to easily perform a scheduled, automated backup of the database. Along comes SQLBackupAndFTP to the rescue! It's free for very small usage, cheap for bigger installations, is easy to use, and has a slew of technical features (automate backups, email notification, zipped files, support for ftp, and a bunch more).

If you need something to automate your MSSQL Express databases, this tool is worth a few minutes of your time to check out.

Sunday, January 16, 2011 7:11:01 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -

# Saturday, January 15, 2011
Rather than another "me too" post on the release of ASP.NET MVC 3, which Hanselman, Haack, and Guthrie have covered in-depth, I thought I'd post the good news that a couple of bugs that have bothered me are fixed in this version.

  1. There was a problem when using auto-detecting view engines when compiling under release mode. Basically, if you hit the site with your desktop browser first, and then come in with the mobile phone, you would still be presented the desktop version. This is now fixed.
  2. I posted about a problem with binding with the RC2 release. This also appears to be fixed.
Throw in the new scaffolding support, and 2011 is shaping up to be a great year for MVC.
Saturday, January 15, 2011 1:25:35 AM (Central Standard Time, UTC-06:00)  #    Comments [3] -
.NET | ASP.NET MVC
# Saturday, January 08, 2011
Here's a short one today, because I know I'll need this again in the future. If you have a MacBook Pro, and you're running Windows via Bootcamp, use this key combination to do a screen grab:
SHIFT + FN + F11

The Apple support article listing a bunch of key mappings can be found here.

Saturday, January 08, 2011 11:17:40 PM (Central Standard Time, UTC-06:00)  #    Comments [2] -
Macintosh
# Monday, January 03, 2011
I recently moved away from shared hosting, and went to a virtual private server in order to scale a site out better. Unfortunately, this meant that I needed to take on more administration of the server to do things that are done for me in a shared hosting environment. One feature that I have come to rely on is one click publishing from VS.NET 2010. In order to make this work, you need to have WebDeploy set up properly.

I found the steps from this page to be very helpful. Another good guide can be found here.

Be careful if you install Web Deploy via the Web Platform Installer. For some reason, when I did this, the Management Service Delegation feature was not installed. I ended up uninstalling and then installing straight from the official site, and the feature was available.

I initially had some settings wrong, and was getting back HTTP 401 and 550 errors. The log files didn't provide much help, but you can add tracing to help diagnose the cause of most issues.

Monday, January 03, 2011 10:12:24 AM (Central Standard Time, UTC-06:00)  #    Comments [0] -
.NET | ASP.NET MVC
# Sunday, December 12, 2010
I updated my web sites to ASP.NET MVC 3 RC2, and started receiving exceptions when model binding. If you want the short version, visit this forum post for the answer. While my errors weren't caused by the same issue that was originally reported in that thread, the fix does work. To sum up even further, just add this line of code in your Global.asax Application_Start method:

ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider(); 

The longer story is that I have a pretty involved multi-step (think "wizard"), deep-level object graph built up over many pages, so I immediately feared that I was unknowingly exploiting some loophole that just got fixed for RC2. I built a test case, so in the interest of not having to build that test case up from scratch again, it looked like this:
Model


public class Foo
    {
        private List<Bar> _bars;
        private List<Baz> _bazs;

        public Foo()
        {
            _bars = new List<Bar>();
            _bazs = new List<Baz>();
        }

        public List<Bar> Bars
        {
            get { return _bars; }
            set { _bars = value; }
        }

        public List<Baz> Bazs
        {
            get { return _bazs; }
            set { _bazs = value; }
        }
    }

    public class Bar
    {
        public int Amount { get; set; }
    }

    public class Baz
    {
        public int Value { get; set; }
    }

Controller


        public ActionResult Index()
        {
            var foo = new Foo();
            foo.Bars.Add(new Bar { Amount = 4});
            foo.Bars.Add(new Bar { Amount = 23 });
            foo.Bars.Add(new Bar { Amount = 30 });
            foo.Bazs.Add(new Baz { Value = 100 });
            foo.Bazs.Add(new Baz { Value = 200 });
            TempData["foo"] = foo;
            return View(foo);
        }

        [HttpPost]
        public  ActionResult Index(IList<Bar> bars, IList<Baz> bazs)
        {
            Foo foo = (Foo) TempData["foo"];
            foo.Bars.Clear();
            foo.Bars.AddRange(bars);
            foo.Bazs.Clear();
            foo.Bazs.AddRange(bazs);
            TempData["foo"] = foo;
            return RedirectToAction("Summary");
        }

        public ActionResult Summary()
        {
            Foo foo = (Foo)TempData["foo"];
            return View(foo);
        }

View


<% using(Html.BeginForm()) { %>
<%
    int barid = 0;
    foreach (var item in Model.Bars){%>

<%= Html.Hidden("Bars.index", barid) %> Bar:<%= Html.TextBox("Bars[" + barid +"].Amount", item.Amount) %> <% barid++; }%> <% int bazid = 0; foreach (var item in Model.Bazs) {%> <br /> <%=Html.Hidden("Bazs.index", bazid)%> Baz: <%=Html.TextBox("Bazs[" + bazid + "].Value", item.Value)%> <% bazid++; }%> <p /> <input type="submit" value="Next" /> <% } %>

I would receive the following call stack when trying to submit the form:


The parameters dictionary contains an invalid entry for parameter 'bazs' for method 
'System.Web.Mvc.ActionResult Index(System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Bar], System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz])'
in 'MvcApplicationRC2.Controllers.HomeController'. The dictionary contains a value of type 'System.Collections.Generic.List`1[MvcApplicationRC2.Models.Bar]', 
but the parameter requires a value of type 'System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz]'.
Parameter name: parameters
Description: 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.

Exception Details: System.ArgumentException: The parameters dictionary contains an invalid entry for parameter 'bazs' for method 
'System.Web.Mvc.ActionResult Index(System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Bar], System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz])'
in 'MvcApplicationRC2.Controllers.HomeController'. The dictionary contains a value of type 'System.Collections.Generic.List`1[MvcApplicationRC2.Models.Bar]', 
but the parameter requires a value of type 'System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz]'.
Parameter name: parameters

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be 
identified using the exception stack trace below.

Stack Trace:

[ArgumentException: The parameters dictionary contains an invalid entry for parameter 'bazs' for method 'System.Web.Mvc.ActionResult
Index(System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Bar], System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz])' in
'MvcApplicationRC2.Controllers.HomeController'. The dictionary contains a value of type 'System.Collections.Generic.List`1[MvcApplicationRC2.Models.Bar]', 
but the parameter requires a value of type 'System.Collections.Generic.IList`1[MvcApplicationRC2.Models.Baz]'.

Parameter name: parameters]
   System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo) +484514
   System.Web.Mvc.<>c__DisplayClass1.<Execute>b__0(ParameterInfo parameterInfo) +18

   System.Linq.WhereSelectArrayIterator`2.MoveNext() +85
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +325
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +78
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +133

   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55

   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19

   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343

   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10

   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12

   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7

   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9

   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Sunday, December 12, 2010 8:29:59 PM (Central Standard Time, UTC-06:00)  #    Comments [2] -
.NET | ASP.NET MVC
# Tuesday, November 23, 2010
After downloading iOS 4.2.1, here are the things that stand out:

  • Apple didn't release a full version of AirPrint. Instead, it's a pretty watered down version that works only against a very select few new HP printers. This is a bit of a disappointment, but there are a couple of 3rd party solutions out there that restore the "print to any networked printer" (Windows and Mac versions are available. I installed and tested the Windows version and it works great. The one hiccup I had was that my firewall didn't automatically prompt me to open up for AirPrint. Once I added it to the exception list, it worked perfectly. If you don't have the Guest account on, you will be prompted for user credentials when printing. I tested both ways, and they both worked fine.
  • I have a web application written using iUI. I noticed that after the upgrade that the look and feel is much different (text boxes in forms are shrunk considerably). I know Mobile Safari underwent some big changes for this upgrade, so I'll need to update the css. I'm looking to convert to jQueryMobile, so this isn't that big of a deal.
  • Initially, I had lost my Google Voice voicemail. I had deactivated and reactivated the voicemail, but I couldn't get it to work. Today, it works fine. So perhaps it was an issue with Google Voice and not iOS 4.2.1

If we could just get voice recognition everywhere like Android, I'd move my satisfaction with the iPhone from 99% to 100%.

Tuesday, November 23, 2010 9:23:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
iPhone
# Tuesday, November 09, 2010
With the near-release of ASP.NET MVC 3, I've been looking at the new Razor view engine. It's quite nicely done and removes the constant "context switching" between code and layout.

In my web site, I used Scott Hanselman's auto-detecting view engine, and it has served me extremely well. However, with the relentless march of technology releases, a couple things should be pointed out:

  • If you want to use Razor on the mobile side, you just need to inherit his original class from RazorViewEngine instead of WebFormViewEngine. (Obviously you should probably do this in a new class, or else the original class name of MobileCapabeWebFormViewEngine will not exactly match up to what the class actually does).
  • The original Mobile Device Browser File project has disbanded. Very sad news, as this was a nice project that kept on top of new smart phones as they were released. It looks like 51 degrees has stepped up to give us an alternative. I opened up an issue to request providing this as a NuGet package. I'll definitely sign up to take this task on if it gains traction, and they want the help.
Tuesday, November 09, 2010 8:04:33 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
.NET | ASP.NET MVC
# Friday, October 15, 2010
Given a method like this, with the following LINQ to SQL statement in it:

public void DisplayReport(UserStatusEnum? userStatus)
...
from user in DBContext.Users
where userStatus == null ? true : userStatus.Value == user.Status
select user

I end up with the error "Nullable object must have a value". Matt Warren (one of the original developers on the LINQ to SQL team, and a wicked smart guy), came up with the idea to use target="_blank">object.Equals(userStatus, user.Status), but that doesn't work for me at all in the case where userStatus is NULL. What worked for me was to do this:


from user in DBContext.Users
where userStatus == null || userStatus == user.Status
select user

The thing is, as one commenter in the linked thread mentioned, LINQ to SQL should be a unifying syntax. We shouldn't have to distinguish between NULL and values just because the underlying provider makes a distinction between the two. I think this is a huge hole, but alas, one that will most likely never be plugged since LINQ to SQL is getting deprecated. Time to check what happens in EF4...

Friday, October 15, 2010 12:41:07 PM (Central Daylight Time, UTC-05:00)  #    Comments [0] -
.NET | LINQ
Navigation
Archive
<January 2011>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2013
Dan Miser
Sign In
Statistics
Total Posts: 391
This Year: 2
This Month: 2
This Week: 0
Comments: 674
Themes
Pick a theme:
All Content © 2013, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)