2

現在、VS2010およびカッシーニを介したJessicaアプリケーションの実行で問題が発生しています。以下のコードは私が実行しているものですが、PUTまたはDELETE動詞を使用しようとすると、405 MethodNotAllowed応答が返されます。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 コンポーネントを入手することをお勧めします。Cassini の癖がなくても、同じ開発体験が得られます。

于 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 ファイルで次の 3 つのエントリを見つけて、コメントを解除します (既定ではコメントになっています)。

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

注: 上記の 3 つの要素は、構成ファイル内の 1 つの場所にはありません。

'</configuration>'2. applicationhost.config ファイルの末尾 ( 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 に答える