MVC 4 Beta + WebApi PUT/DELTE throw 401 on IIS 7.5
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
Setting up IOC for Web Api in MVC 4 Beta
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
Visual Studio Achievements
- 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
- Lonely (5 points)
- Started
- None
- Not Started
- Turtles All The Way Down (0 points)
Write a class with ten levels of inheritance. Now that’s a sweet inheritance! Uses FxCop.
- Field Master (0 points)
Have 100 fields in a single class. Gnarly! Uses FxCop
- Magic Numbers (0 points)
Write a enum with 30 fields. Who needs numbers when you’ve got words! Uses FxCop
- Job Security (0 points)
Write 20 single letter class level variables in one file. Kudos to you for being cryptic! Uses FxCop
- Scroll Bar Wizard (0 points)
Write a single line of 300 characters long. Who needs carriage returns? Uses FxCop
- Localization Guru (10 points)
Have 1000 localized values. Nice localization work!
- Obsessive Compulsive Disorder (OCD) (5 points)
Invoke the ‘Close All But This’ menu option 10 times. I mean, who invented those damn tabs anyway?
- Stubby (5 points)
Generate method stubs 9 times. You’re a TDD bad ass!
- Cheater (5 points)
Invoke an IntelliTrace Menu 10 times. Tools rule! Learn more about Intellitrace.
- Architect (5 points)
Add 10 items to a sequence diagram. You’re not just a developer; you’re an architect! Learn more about sequence diagrams.
- Performance (5 points)
Invoke performance tools 10 times. Why is this app running so slow? Now I know! Learn more about analyzing application performance using profiling tools.
- Time For An Upgrade (10 points)
A solution takes 10 minutes to compile. Dag, that’s one enormous solution!
- Complex (10 points)
Have 50 projects in a solution. That’s kinda scary.
- Using Just What I Need (7 points)
Used ‘Organize Usings’ 50 times. Unused usings are evil!
- UML God (5 points)
Create a UML Class Diagram 10 times. Code is for sissies. Models! Models! Models! Learn more about UML in Visual Studio.
- Potty Mouth (5 points)
Use 5 different curse words in a file. Wash that mouth out with soap!
- Go To Hell (0 points)
Use of the goto keyword. Um, I heard it was a best practice that you weren’t supposed to do that anymore.
- Suspicious (10 points)
Use 5 preprocessor directives. Compiler commands — aren’t you fancy!
- The Explorer (5 points)
Start a debug session using step into (F11) more than 10 times. Ah, the power of F11. Every coder’s best friend.
- Casual Observer (5 points)
Start a debug session using step over (F10) more than 10 times. I thank the debugger every day.
- Equal Opportunist (10 points)
Write a class with public, private, protected and internal members. It’s all about scope. Uses FxCop
- Interrupting Cow (5 points)
Have 10 breakpoints in a file.Where’s that bug? Could here, could be there, could be anywhere!
- Start Me Up (5 points)
Have 3 startup projects. You’ve got a lot on your plate!
- Save A Tree (5 points)
Print source code. My boss told me to. I swear!
- Overload (5 points)
More than 10 overloads of a method. You could go with this or you could go with that. Uses FxCop
- Turtles All The Way Down (0 points)
Microsoft is going All-in with IOS
ASP.NET MVC MapRoute() VS Add()
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
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
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
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?