MVC4

...now browsing by category

 

How to clear the error “ExtensionlessUrlHandler-Integrated-4.0″ has a bad module “ManagedPipelineHandler” in its module list

Monday, December 22nd, 2014

Started with another MVC4 web application that requires Https today and got this error when I tried to browsed the app from local IIS 7:

ExtensionlessUrlHandler-Integrated-4.0″ has a bad module “ManagedPipelineHandler” in its module list

Thanks to this post at http://www.brandonmartinez.com/2014/07/02/resolve-an-http-error-500-21-in-iis/ and followed the instruction to run
regiis, I was able to clear this error and successfully browsed to the local site’s landing page. Here were what I went through (I was on a Win7 x64 bit machine):

  1. All Programs -> Visual Studio 2012 -> Visual Studio Tools
  2. Right clicked on the “Developer Command Prompt for VS2012″ selected “Run as administrator“; this was a must or the next step would not be executed.
  3. Went to directory at C:\Windows\Microsoft.NET\Framework64\v4.0.30319 and ran this command line: aspnet_regiis.exe -i
  4. The whole thing should look like this after done:
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -i
    Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408
    Administration utility to install and uninstall ASP.NET on the local machine.
    Copyright (C) Microsoft Corporation.  All rights reserved.
    Start installing ASP.NET (4.0.30319.18408).
    ....
    Finished installing ASP.NET (4.0.30319.18408).
    
  5. After that, I went back to IIS and re-started the website (which was assigned to a port 44300 for https) then browsed to the landing page and now everything looked pretty.

Observations: @Html.EditorFor and @Html.TextBoxFor in MVC4

Monday, November 24th, 2014

A few tricks learned today when I was working on a email template manager project:

1) If an Action method was marked as [HttpPost] to handle the post event from a form, then there must be a same name Action without [HttpPost] attribute existing in the same controller or you will get a “Page cannot be displayed” error and there was very little debug info to go about.

For example, I have

[ValidateInput(false)]
[HttpPost]
public ActionResult FileUpload(EmailTemplateModel model)
{ //doing files upload }
then I must have a plain action with same name but different signature:

public ActionResult FileUpload()
{
EmailTemplateModel model = new EmailTemplateModel();

model.Attachments= PrepareAttachmentNewModel();

return View(model);

}

or I will get “Page cannot be displayed” error when I try to submit the form with one or multiple “file” html element.

2) Interestingly, when I return the model to view, only when I used @Html.EditorFor, I will be able to render the properties related to the file upload into each textbox; but then the other textboxes will become empty for those fields that were are already there on the form prior to posting the form. Instead, using @Html.TextBoxFor() will retain those values.

Have yet to understand the mechanism underneath, but for now these are my observations and just a quick note first.

Simple fix to error: “Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)”

Friday, October 17th, 2014

After installing SQL Server 2012 and took out SQL server 2008 on local machine last week, today it was first time I tried to load the ..DS.Admin.Web project on local machine and when rendering the Home/Index page, got this error first:

System.MissingMethodException was unhandled by user code

HResult=-2146233069
Message=Method not found: 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)'.
Source=System.Net.Http.Formatting
...
.Web.Admin\Global.asax.cs:line 22

Searched the error “Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)” and led to this post:

http://stackoverflow.com/questions/16756336/method-not-found-void-newtonsoft-json-serialization-defaultcontractresolver-set

So, I first tried this:

Install-Package Newtonsoft.Json –IncludePrerelease
PM> Install-Package Newtonsoft.Json –IncludePrerelease
'Newtonsoft.Json 6.0.5' already installed.
Successfully removed 'Newtonsoft.Json 4.5.1' from Corestream.PPDS.Web.Admin.
Successfully added 'Newtonsoft.Json 6.0.5' to Corestream.PPDS.Web.Admin.

But that led to a different message:

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition d
downloaded 3.5 from http://json.codeplex.com/releases/view/50552 and copied the Newtonsoft.json.dll to
C:\Empower\Development\PPDS2\Corestream.PPDS.Admin\Corestream.PPDS.Web\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll

Thought it might be that I needed to go back to older version of newsoft.json.dll as I am developing this project in VS2010 while some other projects in VS2012; so I went to Newtonsoft site to download the 3.5 version, based on some advice given online. Did that and set the project reference to point to the Newtonsoft.Josn.dll 3.5 version. Not that was not it, still got error about assembly mismatch. Did some more search and found some even suggested removing Newtonsoft.json.dll from GAC. It proved that was nonsense as when I ran this:

Windows+R and typed assembly

The Newtonsoft assembly does not even show up – it is not in GAC, at least for my machine.

Then I tried another smart advice and added this entry to web.config:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.1.0" />
</dependentAssembly>

Well, only bit further, this time got this error:

System.IO.FileLoadException was unhandled by user code
HResult=-2146234304
Message=Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=System.Net.Http.Formatting
FileName=Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
FusionLog=""
....

Well, finally, I realized the best and the simplest solution to this is well under my own nose and I cursed myself for wasting so much time on wandering around on the wild web – so here come the real deal that got me out of this hole:

“The Best Solution is the Simplest Solution” – it proved true again: 

  • Started a brand new project in VS2010 and chose MVC4/Internet Application template as project type.
  • After the project compiled and flied smoothly, rendering that nice Home page that has been missing for hours from me, I checked the project’s references and noticed that now it pointed to a 4.5.6 version of Newtonsoft.Json.dll, instead of 4.5.1 or 4.5.0 that I used in the troubled project. This is in the new project’s packages folder.
  • So I just went back to the troubling project and changed the reference to point to here at this 4.5.6 version that was brought in with the mighty MVC4/Internet Application wizard for my dummy project, and as I expected, everything just went back to normal and it ended my Friday afternoon on a happier note.