0

I have a Web.config file in my .NET Framework app hosted on IIS. Inside the Web.config, I have a location element like so:

...
<location path="Controllers/api">
    <appSettings>
        <add key="secrectMessage" value="myAwesomeValue"/>
    </appSettings>
    <system.web>
        <httpRuntime executionTimeout="300"/>
    </system.web>
</location>
...

secretMessage is just for testing, what I really want is the timeout. My goal is to have the executionTimeout apply to only one API controller file, or even just one endpoint if possible. (I could split out that endpoint to its own file if files are as specific as Web.config will go.) Using the structure above, when I go to IIS Manager and navigate to the Controllers/api folder, and click Application Settings, I am able to see the secretMessage/myAwesomeValue. Does this mean that the executionTimeout is also set at this directory? I don't see any confirmation of that in the Manager UI.

When I change the path value to "Controllers/api/MyController.cs" I can't confirm the setting in the Manager UI because I can only navigate to directories. (It seems like every example of <location> has an .aspx file. Is there a reason for this?) Would changing the path to include the .cs file work to change the settings on calls made to this controller? Is there a way to specify Web.config settings for just one endpoint inside the controller?

Edit: I came up with another idea, which is to break the controller into two partial class files, one inside an addition directory Controllers/api/extendedTimeout to be able to apply the config to that directory. This seems to have done the same thing as far as I can tell in IIS Manager. Though, in the C# in Controllers/api/extendedTimeout/MyControllerExtension.cs, I have `ConfigurationManager.AppSettings["secrectMessage"];' but this returns null.

  • ExecutionTimeout apply to only one API controller file. If you want to implement something like set different Timeouts for every URLs. Here is a similar program: https://stackoverflow.com/a/6588864/20058276. – TengFeiXie Apr 07 '23 at 08:19
  • "I don't see any confirmation of that in the Manager UI." In the IIS manager, the setting you can see is the connection timeout in the advanced settings, and you can also find it in the web.config in the root directory of IIS. ConnectionTimeout, specifies the time (in seconds) that IIS waits before it disconnects a connection that is considered inactive. ExecutionTimeout, specifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET. – TengFeiXie Apr 07 '23 at 08:19

0 Answers0