question

BrandonHendricksLSUHSC avatar image
0 Votes"
BrandonHendricksLSUHSC asked BrandonHendricksLSUHSC edited

IIS / .Net 6 / AspNetCoreV2 / 405 Method Not Allowed

I am developing a REST API using Web API with .Net 6. My server is Windows 2012 R2 / IIS 8.
GET, POST, and PUT work without issue. When attempting DELETE, I get a 405 Method Not Allowed. I did failed request tracing and can confirm the issue is happening with the AspNetCoreModuleV2.
After doing a lot of searching and trying possible solutions: WebDAV is not installed on the system. I have tried selecting "All verbs" and as well as adding each individual verb in the Handler Mapping section.
Any other suggestions on getting DELETE to work?

windows-server-iisdotnet-aspnet-core-generaldotnet-aspnet-core-webapi
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Most likely an issue with your code. Is there anyway you can share the Delete method and client code so we can see what you're doing?

1 Vote 1 ·

Here is the JavaScript / jQuery code:

             $.ajax({
                 url: 'api/supportgroups/'+group,
                 type: 'DELETE',
                 dataType: 'text'
             })

And here is the API code:

 app.MapDelete("supportgroup/{id}", async (string id, supportgroupsDB db) =>
 {
     if (await db.supportgroup.FromSqlRaw($"select * from groups where supportgroup='{id}'").ToListAsync() is List<SupportGroup> supportgroup)
     {
         await db.Database.ExecuteSqlRawAsync($"delete from groups where supportgroup='{id}'");
         return Results.Ok(supportgroup);
     }
     else
     {
         return Results.NotFound();
     }
 });


0 Votes 0 ·

And right after pasting both these blocks, I realized the API url says supportgroup rather than supportgroups . I'm about to update my code and see what happens.

Edit: That fixed it. Thanks.

0 Votes 0 ·

1 Answer

SamWu-MSFT avatar image
0 Votes"
SamWu-MSFT answered BrandonHendricksLSUHSC commented

@BrandonHendricksLSUHSC

If you don't need to use WebDAV, then the easiest and the best way to fix "405 method not allowed" issue is to remove WebDAV from your system. You can easily get this done in "Turn Windows Features On or Off" simply un-ticking the checkbox.

203914-1.png


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1.png (18.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, but WebDAV is not installed.

0 Votes 0 ·