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 =&开发者_Go百科gt;
{
DeleteUser(r.id);
return Response.AsRedirect("/user");
});
}
}
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.
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
精彩评论