2

I am currently having an issue running a Jessica application via VS2010 and Cassini. The code below is what I am running however when I attempt to use either PUT or DELETE verbs I get a 405 Method Not Allowed response. I tried the answer suggested at ASP.NET MVC got 405 error on HTTP DELETE request? but this did not work for me. I have also copied in my minimal web.config

<?xml version="1.0"?>

<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>

Code

public class UserModule : JessModule
{
    public UserModule() : base("/user")
    {
        Get("/", r => View("list", UserRepository.GetAllUsers()));

        Post("/", r =>
        {
            AddUser(new User { EmailAddress = r.EmailAddress, Name = r.Name });
            return Response.AsRedirect("/user");
        });

        Get("/edit/:id", r => View("edit", UserRepository.GetUser(int.Parse(r.id))));

        Put("/:id", r =>
        {
            EditUser(r.id, new User { EmailAddress = r.EmailAddress, Name = r.Name });
            return Response.AsRedirect("/user");
        });

        Delete("/:id", r =>
        {
            DeleteUser(r.id);
            return Response.AsRedirect("/user");
        });
    }
}
Community
  • 1
  • 1
James Hughes
  • 6,006
  • 4
  • 29
  • 41

2 Answers2

2

I'm pretty sure it's always been like that, the ASP.NET development server has its limits. I would recommend getting VS2010 SP1 and the IIS Express components through the Platform Web Installer. It will give you the same development experience without the quirks of Cassini.

John Leidegren
  • 56,169
  • 16
  • 118
  • 148
0

Put verb should work with IIS Express and for this you need to enable WebDAV (IIS Express installs WebDAV but it does not enable it by default). And also WebDAV does not work with anonymous authentication. So you need to enable WebDAV, disable anonymous authentication and enable Windows Authentication. Follow below steps;

1.Find following three entries in the applicationhost.config file located in user profile(%userprofile%\documents\iisexpress\config\applicationhost.config) and un-comment them (by default they are commented)

<add name="WebDAVModule" image="%IIS_BIN%\webdav.dll" />
<add name="WebDAVModule" />
<add name="WebDAV" path="*" verb="PROPFIND,PROPPATCH,MKCOL,PUT,COPY,DELETE,MOVE,LOCK,UNLOCK" modules="WebDAVModule" resourceType="Unspecified" requireAccess="None" />

Note: Above three elements are not at one place in the configuration file.

2.Add following configuration entry at the end of the applicationhost.config file (Just before '</configuration>' element )

<location path="WebSite1"> 
    <system.webServer>
        <security>
            <authentication>
            <windowsAuthentication enabled="true" useKernelMode="false">
                    <providers>
                        <clear />
                        <add value="Negotiate" />
                        <add value="NTLM" />
                    </providers>
                </windowsAuthentication>
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
        <webdav>
            <authoring enabled="true" />
            <authoringRules>
                <add users="*" path="*" access="Read, Write, Source" />
            </authoringRules>
        </webdav>
    </system.webServer>
</location>

Note: In the above config entry replace 'WebSite1' with your site name

3.Restart IIS Express

4.Now try PUT/DELETE request

vikomall
  • 16,953
  • 6
  • 44
  • 38
  • A quick google of the topic reveals that WebDAV should not be used, and is in fact causing trouble and i would advice against it. It is likely that this is a simple configuration issue that has to be done to allow more http verbs by default. – John Leidegren May 19 '11 at 18:29
  • why WebDAV should not be used? could you share the link which advices not to use it. I beleive there is no default handler in IIS for PUT verb! – vikomall May 19 '11 at 23:13
  • See this thread http://forums.iis.net/t/1166025.aspx and this one http://forums.iis.net/t/1163441.aspx they explicitly go into details on how WebDAV is the culprit – John Leidegren May 20 '11 at 05:58
  • It's true that WebDAV claim PUT/DELETE etc... verbs. If you have any other module which claim these verbs, then it would be an issue. Othewise you can use WebDAV. – vikomall May 20 '11 at 14:41