test

May 29, 2012 Leave a comment
Categories: .NET

MVC 4 Beta + WebApi PUT/DELTE throw 401 on IIS 7.5

May 10, 2012 Leave a comment

Kinda crazy that everything works fine on localhost, however once deployed to UAT, as soon as the Ajax hitting the PUT/DELETE it throw 401 while GET/POST stays working as it should

After some diggings seems it’s to do with WebDAV, you can search for the topic “Allowing PUT and DELETE in IIS 7.5”.

PUT and DELETE are considered as WebDAV verb and webdav module claims the request. basically, webdav cannot be set with other module like RESTFul also handling WebDAV specific verbs. ie. PUT, DELETE, COPY.etc

Disable webdav on site does not resove your concern.
Solution is to uninstall webdav module. If OS is Vista or W2K8, then go to control panel/Add Remove Program, and remove webdav.
If OS is Win7, for server machine, Server Manager -> Role -> Web Server -> Common HTTP Features -> WebDAV Publishing, and for client machine Control Panel -> Uninstall Program -> Turn Windows features on or off -> IIS -> World Wide Web Services -> Common HTTP feautre -> WebDAV Publishing.

Found a post about this http://forums.iis.net/t/1163441.aspx

I will give it a shot tomorrow and prepare for the worst and the fall-back would be POST!

Update:
Yes everything works like a charm! simply by removing WebDAV from IIS 7.5

Categories: .NET Tags: , , , , ,

Setting up IOC for Web Api in MVC 4 Beta

March 7, 2012 Leave a comment

VS11 beta and MVC 4 beta just came out and I have converted to at least 2 MVC 3 projects to MVC 4 beta. The conversion has been really smooth. 

In the meantime I’m rewriting some functions using the new Web API, it’s really just a WCF RESTful, nothing too exciting there. However The new ApiController doesn’t work with the current implementation of IOC. cause it’s inheriting from a different base classes as MVC Controllers.

After some Googling, realising that it’s using System.Web.Http.Dispatcher.IHttpControllerFactory and System.Web.Http.Dispatcher.IHttpControllerActivator to create the controllers.

I actually did managed to get the IOC working in a quick nasty fashion,  still looking for a elegant implementation.

Now the ApiControllers are derived from IHttpController a simple interface that has a solo Task in it whereas MVC Controller are from ControllerBase -> IController which is an abstract class. big difference there!

Apparently your existing MVC DependencyResolver.SetResolver() won’t do the job anymore – ALONG! because it only resolves System.Web.Mvc.IDependencyResolver.

So in order to activate ApiController, it will requires to things. 1. Implementing the IServiceLocator. 2. Using the new System.Web.Http.GlobalConfiguration.
which shipped within the same DLL as ApiController.

Now the good news is StructureMap 1.1.0 did a great job that already shipped a new updates that gives your the IServiceLocator implementation, so you can simply take your IContainer intacted and go like new StructureMapServiceLocator(container)

So the final line is System.Web.Http.GlobalConfiguration.ServiceResolver.SetResolver(new StructureMapServiceLocator(container)); !

This will take care of all your ApiControllers, you’ll still need the DependencyResoler.SetResolver() line to take care of all the mvc controllers

Windows 8 Consumer Preview & Visual Studio 11 Beta Launched Today!

March 1, 2012 Leave a comment

Visual Studio Achievements

January 20, 2012 Leave a comment
  • Completed
    • Lonely (5 points)

      Code on a Friday or Saturday night. Coding? Tonight? Ouch.

      12 minutes ago

    • Regional Manager (7 points)

      Add 10 regions to a class. Your code is so readable, if I only didn’t have to keep collapsing and expanding!

      5 hours ago

    • On The Shoulders of Giants (10 points)

      Reference 25 assemblies. Hey, why should you write it if someone else already did?

      5 hours ago

    • Gotta Be Different (5 points)

      Load custom Visual Studio settings. I swear, they never get the default settings right.

      5 hours ago

    • Install and Register For Visual Studio Achievements (5 points)

      Install the add-in and register with Channel9. You are up and running!

      5 hours ago

    • Extensions Junkie Deluxe (10 points)

      Install 10 extensions to Visual Studio. How can you find anything on a menu?

      5 hours ago

    • Extensions Junkie (5 points)

      Install 5 extensions to Visual Studio. Extensibility rocks!

      5 hours ago

  • Started
    • None

Microsoft is going All-in with IOS

December 15, 2011 Leave a comment

ASP.NET MVC MapRoute() VS Add()

December 12, 2011 Leave a comment

Ever wondering what’s the difference between routes.MapRoute() vs routes.Add()? I’m gotta hitting the bed soon, so I’ll keep it short.

Basically, MapRoute is an extension method in RouteCollectionExtensions.cs, It’s really a helper of routes.Add(),

[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "2#", Justification = "This is not a regular URL as it may contain special routing characters.")]
        public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) {
            if (routes == null) {
                throw new ArgumentNullException("routes");
            }
            if (url == null) {
                throw new ArgumentNullException("url");
            }

            Route route = new Route(url, new MvcRouteHandler()) {
                Defaults = new RouteValueDictionary(defaults),
                Constraints = new RouteValueDictionary(constraints),
                DataTokens = new RouteValueDictionary()
            };

            if ((namespaces != null) && (namespaces.Length > 0)) {
                route.DataTokens["Namespaces"] = namespaces;
            }

            routes.Add(name, route);

            return route;
        }

You see what it does is to process the incoming request handing over to MvcRouteHandler() which ultimately derived from IHttpHandler. It’s merely another request handler!

So when you are rolling your own IHttpHandler ie. ImageHandler. and trying to process certain requests using it. You totally can go straight to route.Add(“AwesomeImageHandler”, “Image/{filename}/{width}/{height}”, new MyAwesomeImageHandler()) – as long as your AwesomeImageHandler implements IRouteHandler

IRouteHandler has one single interface in it – public IHttpHandler GetHttpHandler(RequestContext requestContext)

See what it actually returns is an IHttpHandler, cool, if you already have an ImageHandler that made for Webform you can pretty much chuck it in!

In case your old ImageHandler is using System.Drawing.Image, time to upgrade it to WebImage, it’s so cool

Check in Nuget packages to source controls

December 5, 2011 Leave a comment

There are two ways to check in Nuget packages to source controls. ie TFS, SVN. And it turns out neither of them is perfect.

You can add the whole local packages to TFS/SVN, just as how you would do it with external assemblies without Nuget. In TFS it would be easier if you installed power tools which has a windows explorer shell allows you to add files in the SVN style. This the the old school style which always works, and everyone will get exactly the same assemblies and cut the dependency to the internet based Nuget repository.

I don’t see anything wrong with this approach it makes your source control has everything. and make your sources mobile friendly, you don’t need an internet connections in order to get the assemblies as long as you have access to your source control. (ie. in the VM)

Another way of doing it if bit cooler and sounds more recommended. Basically you don’t check in the packages folder at all (same reason as you don’t check in your bin folders). each project has packages.config which contains all the assembly references. That’s basically all you need. Then you’ll need to write some prebuild scripts to get all the assemblies from the internet Nuget repository.

NuGet install NuGetDemo\packages.config -o Packages

You’ll also need to check in Nuget command line utility in order to execute such command. and it will skip the package that already exist on your local. Now this is cooler but with problems too. firstly it requires an internet connection. secondly what if the package author removed his package from the Nuget??? You’re pretty much screwed! Although lets assume that this is pretty rarely happened but possible.

I hope Phil Haack can come up with a better package version management way to solve this problem.  Until then I think I’ll stick with the old-fashion way cause that works anytime anywhere effortlessly considering I have a mobile work station that doesn’t always connect to the internet. I love writing all the cute little utility tool but only if they serve a good purpose.

New build server “Microsoft.WebApplication.targets” was not found

December 4, 2011 Leave a comment

Just setup a brand new build server with Windows 2008 R2 with TFS 2010 and SQL 2008 R2.

All good except it keep complaint about “Microsoft.WebApplication.targets” was not found When trying to build a web project.

“C:\Builds\1\GrouponSharp\CI\Sources\trunk\GrouponSharp.Web\GrouponSharp.Web.csproj (377): The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.”

Answer was obvious the error says it all. but what do I need to install to get this build target?

Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package

After installed, the webapplication build target will be appeared in the right directory.

Or even better, you can just install the TFS2010 team explorer on the build server which will install VS 2010 shell redistributable package for you along with other goodies like VS prerequisites.

You don’t need to install the actually visual studio 2010 on your build server like just in order to get this assembly, like some answer you might find on internet.

Scott Hanselman’s 2011 Ultimate Developer and Power Users Tool List for Windows

December 1, 2011 Leave a comment

 

A comprehensive collection of tools for dev and power users made by Scott Hanselman.

 

2011 Ultimate Developer and Power Users Tool List for Windows

 

NOTE: Please don’t reproduce this in its entirety, I’d rather you link to http://hanselman.com/tools. I appreciate your enthusiasm, but posts like this take a lot of work on my part and I’d appreciate that work staying where it is and linked to, rather than being copy/pasted around the ‘net. If you’re reading this content and you’re not at http://hanselman.com, perhaps you’d like to join us at the original URL?