Can I group appseting keys? - grouping

I'm creating a little console application that creates a Lucene index from an Sql Database.
This application will be run with a single parameter. This parameter will define what connection string it will use and where the destination file should be placed.
I would like to store the connection strings and the target paths in the app.config file.
Is it possible to group settings somehow? For example I would like that if the parameter "ABC" is given, connectionstring1 is used and targetPathBanana is used.
This following example doesn't work but I think illustrates my intention
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<abc>
<appSettings>
<add key="targetBasePath" value="\\Thor\lucene\abc"/>
</appSettings>
<connectionStrings>
<add name="commonString"
connectionString="Data Source=thor;Persist Security Info=True;User ID=****;Password=****"/>
</connectionStrings>
</abc>
<123>
<appSettings>
<add key="targetBasePath" value="\\Loki\temp\lucene"/>
</appSettings>
<connectionStrings>
<add name="commonString"
connectionString="Data Source=helga;Persist Security Info=True;User ID=****;Password=****"/>
</connectionStrings>
</123>
</configuration>
I know I could just make the names of the keys follow a naming convention, but I'm curious if this could be solved in a way that's less convention-based.

If you use this prefix in your app.config file, you should be able to create as many custom section groups that contain <appSettings> and <connectionStrings> sections as you wish:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="ABC">
<section name="appSettings"
type="System.Configuration.AppSettingsSection,
System.Configuration"/>
<section name="connectionStrings"
type="System.Configuration.ConnectionStringsSection,
System.Configuration"/>
</sectionGroup>
</configSections>
... put your section groups here.....
<ABC>
<appSettings>
<add key="targetBasePath" value="\\Thor\lucene\abc"/>
</appSettings>
<connectionStrings>
<add name="commonString" connectionString="..."/>
</connectionStrings>
</ABC>
</configuration>

Related

Increase timeout setting for Flask Application

I have a flask application which I have configured to run on IIS7. I am using web.config file for the required flask configuration and is working great.
In my application I have a section where the user can upload a data file which for processing; per my processing needs this might take more time depending on the file size and for a bigger file the app is timing out.
I need to set the time out to a bigger number. Need help.
here is my web.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="Python27_via_FastCGI" />
<remove name="Python34_via_FastCGI" />
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="d:\anaconda3\python.exe|d:\anaconda3\lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="gui.app" />
<add key="PYTHONPATH" value="D:\PythonProjects\FlaskApp" />
</appSettings>
</configuration>
You can increase the timeout value in flask itself, try the following:
import requests
timeoutSeconds = 5
try:
res = requests.get(<url>, timeout=timeoutSeconds)
except:
print("Timeout")

I am facing issues while hosting my Flask web application in IIS

I am using Python3.5, IIS10 to deploy flask web application in iis. Can anyone help me to set up iis with python. I saw many examples but i could not able to do so. I guess the error must be related to web.config
My error is
HTTP Error 500.0 - Internal Server Error C:\Program Files\Python35\python.exe - The FastCGI process exceeded configured request timeout
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="Bot_Chat.app" />
<add key="PYTHONPATH" value="C:/inetpub/wwwroot/EtownChatBot/;C:\Program Files\Python35;C:\Program Files\Python35\Lib;C:\Program Files\Python35\Lib\site-packages;C:\Program Files\Python35\DLLs;" />
</appSettings>
<system.webServer>
<handlers>
<remove name="CGI-exe" />
<add name="FlaskHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files\Python35\python.exe|"C:\inetpub\wwwroot\EtownChatBot\wfastcgi.py"" resourceType="Unspecified" />
</handlers>
<directoryBrowse enabled="true" />
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".py" allowed="true" />
<add fileExtension=".html" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Add applicationHost.xdt under Your Project directory..
applicationHost.xdt
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<fastCgi>
<application xdt:Locator="Match(fullPath)" xdt:Transform="SetAttributes(activityTimeout)"
fullPath="C:\Program Files\Python35\python.exe" activityTimeout="600"/>
</fastCgi>
</system.webServer>
</configuration>
Refresh and Restart your Site.Now it will work..

Is it possible to modify http request timeout in Azure App Service - Django

Currently this value is around 80 seconds. I tried modifying the timeout by multiple ways:
Modifying the web.config file.
<system.web>
<httpRuntime targetFramework="4.5" executionTimeout="600"/>
</system.web>
Modifying SCM_COMMAND_IDLE_TIMEOUT value in application settings in azure portal.
One more solution I got here:
https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/. I think this doesn't apply to Azure app service.
None of these are working. Is there a way we can modify timeout value?
Change your config as per below for Python.
Set the desired requestTimeout="00:04:00"
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*"
modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="D:\home\Python27\python.exe" arguments="manage.py runserver %HTTP_PLATFORM_PORT%" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
<environmentVariables>
<environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Read details https://prmadi.com/django-app-with-httpplatformhandler-in-azure-app-services-windows/

ASP proper config to allow CORS in a asmx webservice for POST requests

I´m trying to setup a server capable to handle CORS, but also capable to return the response in json format.
Tried with various config schemes, but no luck.
I need to do my Ajax requests via POST. With my actual config i´m able to do requests via GET, but currently my response always is encapsulated in XML format.
As stated in ResponseFormat.Json returns xml , my requests must be 'application/json' but when I try to do it in this way I'm receiving a preflight message (Response for preflight has invalid HTTP status code 404).
My web.config (allowing CORS via GET) currently is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2">
<assemblies>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<!--<add assembly="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>-->
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</assemblies>
</compilation>
<httpRuntime />
<pages controlRenderingCompatibilityVersion="4.0" />
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</httpHandlers>
<sessionState timeout="30"></sessionState>
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
<appSettings>
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
</appSettings>
<connectionStrings>
<....>
</connectionStrings>
<system.webServer>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" /><remove name="OPTIONSVerbHandler" /><remove name="TRACEVerbHandler" /><add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /></handlers>
<validation validateIntegratedModeConfiguration="false" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
I´m using iron-polymer for the Ajax-requests and combined various content-types. Currently i´m getting my data via GET using 'content-type="application/x-www-form-urlencoded; charset=UTF-8" handle-as="document"'.
I´m having difficulties to process the response due such XML encapsulation. Below are two examples of received responses. How to extract the contents ?
1:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://my.domain/">EF7B48E346BC537F98F9696304CECAFE</string>
2:
'<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCiudad xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://my.domain/">
<Ciudad>
<Codigo>32</Codigo>
<Nombre>BOGOTA</Nombre>
<CodigoDepartamento>Z03</CodigoDepartamento>
</Ciudad>
<Ciudad>
<Codigo>133</Codigo>
<Nombre>CALI</Nombre>
<CodigoDepartamento>Z01</CodigoDepartamento>
</Ciudad>
<Ciudad>
<Codigo>53</Codigo>
<Nombre>CARTAGENA</Nombre>
<CodigoDepartamento>Z13</CodigoDepartamento>
</Ciudad>
<Ciudad>
<Codigo>30</Codigo>
<Nombre>MEDELLIN</Nombre>
<CodigoDepartamento>Z04</CodigoDepartamento>
</Ciudad>
</ArrayOfCiudad>'

deployment of a web.config to amazon beanstalk

When I deploy a .net web application to Amazon Beanstalk, my local web.config gets completely ignored and it just gets replaced with this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="PARAM3" value="" />
<add key="PARAM4" value="" />
<add key="PARAM1" value="" />
<add key="PARAM2" value="" />
<add key="PARAM5" value="" />
<add key="AWS_SECRET_KEY" value="" />
<add key="AWSSecretKey" value="" />
<add key="AWS_ACCESS_KEY_ID" value="" />
<add key="AWSAccessKey" value="" />
</appSettings>
</configuration>
I thought that beanstalk wasn't able to parse some section of my web.config so I simplified the web.config to the minimum:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="mykey" value="myvalue"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
And I get the same result. my appSettings and every other section of my web.config don't appear in the web.config that gets deployed.
I looked everywhere and I can't find documentation on this.
I don't have any transforms in my local application (i.e. no web.release.config file).
Can I disable this "feature" of Beanstalk somehow?
I don't ask for any action, I just want my original web.config deployed.
Set the environment variables in the Elastic Beanstalk console, not in your git repository.