2

我目前在通过 VS2010 和 Cassini运行Jessica应用程序时遇到问题。下面的代码是我正在运行的代码,但是当我尝试使用 PUT 或 DELETE 动词时,我得到一个 405 Method Not Allowed 响应。我尝试了ASP.NET MVC 在 HTTP DELETE 请求上出现 405 错误建议的答案?但这对我不起作用。我还复制了我的最小 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>

代码

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");
        });
    }
}
4

2 回答 2

2

我很确定它一直都是这样,ASP.NET 开发服务器有其局限性。我建议通过 Platform Web Installer 获取 VS2010 SP1 和 IIS Express 组件。它将为您提供相同的开发体验,而没有卡西尼的怪癖。

于 2011-05-19T11:41:03.913 回答
0

Put 动词应该与 IIS Express 一起使用,为此您需要启用 WebDAV(IIS Express 安装 WebDAV,但默认情况下不启用它)。而且 WebDAV 也不适用于匿名身份验证。所以你需要启用 WebDAV,禁用匿名身份验证并启用 Windows 身份验证。请按照以下步骤操作;

1.在位于用户配置文件(%userprofile%\documents\iisexpress\config\applicationhost.config)的applicationhost.config文件中找到以下三个条目并取消注释它们(默认情况下它们已注释)

<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" />

注意:以上三个元素不在配置文件中的一处。

2.在 applicationhost.config 文件末尾添加以下配置条目(就在'</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>

注意:在上面的配置条目中,将“WebSite1”替换为您的站点名称

3.重启IIS Express

4.现在尝试 PUT/DELETE 请求

于 2011-05-19T16:52:59.477 回答