2

I have a webapi 2.0 which I am publishing using ftp to my windows 2012 server running IIS 8.5.

I ran into an issue which I can resolved using this link here;

Error 405 – Methods not Allowed in ASP.NET Core PUT and DELETE requests

so by adding;

<modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
</modules>

I can fix my PUT and DELETE issues, however whenever I publish I am having to physically edit the web.config to reflect the addition of the above code?

Can anyone tell me how to automatically add this when I publish using ftp with web deploy?

My program.cs has the default build in it;

        public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
3
  • In one of my deployments I have a Powershell script to modify the contents of web.config, then I execute it as a pre-publish target. Commented May 2, 2018 at 14:47
  • ok do you have an example you could post I can live with that solution? I assume there no way to pipe into the process when its created then? Commented May 2, 2018 at 14:53
  • There could be, I'm just not aware of it. web.config isn't really part of ASP.NET Core, it's just there for IIS compatibility. I get the impression it wasn't meant to be edited. Commented May 2, 2018 at 15:00

1 Answer 1

1

One solution I've done is to create a Powershell script that will modify your web.config file however you need and execute it as a Pre-publish Target.

Keep the script in your project directory and update the .csproj file so that it will run just before publishing the project:

Left click project name in Visual Studio -> "Edit .csproj" and insert this somewhere inside the <Project> tags:

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
    <Exec Command="powershell.exe -NonInteractive -File Prepublish.ps1" />
</Target>

Edit: My task was simpler, I just needed to remove the LAUNCHER_ARGS added to the <aspNetCore> element, so I just did a simple string replace with an empty string,

Prepublish.ps1:

(Get-Content web.config).Replace(" arguments=`"%LAUNCHER_ARGS%`"", "") | Set-Content web.config
Sign up to request clarification or add additional context in comments.

3 Comments

Out of interest how do you edit the file to add it in the correct location?
Sorry I meant do you have an example of your powershell script?
I added mine, but my modification wasn't quite as involved as yours so a slightly different approach might be needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.