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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: