Regex pattern to read an Web.config - regex

I need your valuable help, in reading a connection string value using regex -
Idea is to read the pattern using saltstack state file, and replace with VSTS variable.
Could you please help , how can I read the value ?
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication45-20140804053515.mdf;Initial Catalog=aspnet-WebApplication45-20140804053515;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization"
</entityFramework>
</configuration>
Below is my salt state file :
Thanks,

I use a Powershell script to replace the values of the connection string in the web.config.
After I "catch" the connection string I run this code:
$dbServer = [regex]::Match($connection, '(?i)data source=([^;]+)').Groups[1].Value
$newConnection = $connection.Replace($dbServer+';', $newSqlServerName+';')
$dbName = [regex]::Match($connection, '(?i)initial catalog=([^;]+)').Groups[1].Value
$newConnection = $newConnection.Replace($dbName+';', $newDbName+';')
So the Regex is:
For Data Source: (?i)data source=([^;]+)
For Initial Catalog: (?i)initial catalog=([^;]+)
For User name: (?i)user id=([^;]+)
For Password: (?i)password=([^;]+)

Related

Nuget Server Repository - Page not found 404

I'm totally desperate. I've been trying to install Nuget.Server v3.2.1.0 for two days now.
I followed the installation instructions at https://learn.microsoft.com/de-de/nuget/hosting-packages/nuget-server, but it doesn't work.
I suspect that the routing doesn't work properly.
My Web.config looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation strict="false" explicit="true" debug="true" targetFramework="4.6" />
<!-- maxRequestLength is specified in Kb -->
<httpRuntime targetFramework="4.6" maxRequestLength="30720" />
</system.web>
<appSettings>
<add key="aspnet:UseHostHeaderForRequestUrl" value="true" />
<add key="requireApiKey" value="true" />
<add key="apiKey" value="MyApiKey" />
<add key="packagesPath" value="D:\TFS-Workspaces\Fachit360\Playground\NuGet Server\NuGet Server\Packages" />
<add key="cacheFileName" value="" />
<add key="allowOverrideExistingPackageOnPush" value="false" />
<add key="ignoreSymbolsPackages" value="true" />
<add key="enableDelisting" value="false" />
<add key="enableFrameworkFiltering" value="false" />
<add key="enableFileSystemMonitoring" value="true" />
<add key="allowRemoteCacheManagement" value="false" />
<add key="initialCacheRebuildAfterSeconds" value="15" />
<add key="cacheRebuildFrequencyInMinutes" value="60" />
</appSettings>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.webServer>
<handlers>
<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" />
<remove name="WebDAV" />
</handlers>
<staticContent>
<remove fileExtension=".nupkg"/>
<mimeMap fileExtension=".nupkg" mimeType="application/zip" />
</staticContent>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="31457280" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
</assemblyBinding>
</runtime>
</configuration>
And here is my development environment:
- Visual Studio 2017 Pro (15.9.12)
- Windows 10 Enterprise LTSC
- IIS Express 10.0 (Visual Studio integrated)
The installation is very simple. The overview page is also displayed:
What I find confusing is that the Default.aspx file contains the following:
Click here to view your packages.
And in the file NuGetODataConfig.cs the following is configured:
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
config,
"NuGetDefault,
"nuget"
"PackagesOData,
enableLegacyPushRoute: true);
Anyway, when I click on "Click here to view your packages", I get the error: "Page not found - 404".
Does anyone have an idea why that might be? I am at the end of my Latin.
Many greetings
Update
I forgot to mention that I also tried to release the project on a Windows Server 2012 R2. Exactly the same problem.
And it's strange that you can find the following packages in my project references:
- Nuget.Core
- Nuget.server
- Nuget.Server.Core
- Nuget.Server.V2
Then why does the start page talk about Nuget.Server 3.2.1.0?

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..

How to call a RESTFul web service with a parameter that has a "dot" inside

I developed a RESTFul service but I am having problems when I want to pass a parameter that has a dot in it. I tried encoding the URL, replacing the dot by %2E, but the end point is not found. When I remove the dot, the end point is found, so it is obvious that something is wrong with the dot.
for example, this request works:
http://localhost:9999/SvcLipigas.svc/AlmacenaPedido/229188562/16122016/2030/123456/CILINDRO%2015%20KGCODIGAS/2/14000/15/19122016/1514/19122016/1000
But this other one does not:
http://localhost:9999/SvcLipigas.svc/AlmacenaPedido/229188562/16122016/2030/123456/CILINDRO%2015%20KG%2ECODIGAS/2/14000/15/19122016/1514/19122016/1000
Notice the dot in the "CILINDRO%2015%20KG%2ECODIGAS" parameter.
Any help will be appreciated.
Currently, as a patch, I am sending the dot replaced by a pipe character, and in the service, I am replacing it back to the dot, but this is a very ugly solution.
EDIT:
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "AlmacenaPedido/{telefono}/{fechaPedido}/{horaPedido}/{codigoInterno}/{descripcionProducto}/{cantidadProducto}/{valorUnitario}/{kilosProducto}/{fechaEntrega}/{horaEntrega}/{fechaDespacho}/{horaDespacho}")]
int AlmacenaPedido(string telefono, string fechaPedido, string horaPedido, string codigoInterno, string descripcionProducto,
string cantidadProducto, string valorUnitario, string kilosProducto, string fechaEntrega, string horaEntrega,
string fechaDespacho, string horaDespacho);
EDIT: This is the full web.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WS_PedidoCliente.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WS_PedidoCliente.SvcLipigas" behaviorConfiguration="serviceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="WS_PedidoCliente.ISvcLipigas"
bindingNamespace="http://ws.lipigas.cl"
behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="LipigasEntities" connectionString="metadata=res://*/Model.Lipigas.csdl|res://*/Model.Lipigas.ssdl|res://*/Model.Lipigas.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=SLLCOSTO;PASSWORD=uni_1915sll;USER ID=PEDIDO"" providerName="System.Data.EntityClient" />
</connectionStrings>
<applicationSettings>
<WS_PedidoCliente.Properties.Settings>
<setting name="Usuario" serializeAs="String">
<value>EMDITEC</value>
</setting>
</WS_PedidoCliente.Properties.Settings>
</applicationSettings>
</configuration>
This is a limitation of IIS.
It is treating the dot (encoded or not) as an extension.
Try adding
<httpRuntime relaxedUrlToFileSystemMapping="true" />
to the web.config

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>'

System.Web.HttpException: Failed to Execute URL when running web service, MVC3

I have converted ASP.NET application to run ASP.NET and MVC 3 together. And there is some web service (/WS/Inventory.asmx/getInventory) that shows the following exception now:
System.Web.HttpException: Failed to Execute URL.
[HttpException (0x80004005): Failed to Execute URL.]
System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state) +2428801
System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state) +417
System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +192
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862676
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
I running it on Windows 7 with IIS 7 though there is the same exception on Windows 2003.
Here is web config section:
<system.webServer>
<defaultDocument>
<files>
<add value="index.aspx" />
</files>
</defaultDocument>
<httpErrors errorMode="Detailed" />
<modules runAllManagedModulesForAllRequests="true">
<add name="OverloadProtection" type="Winncom.Classes.HttpModules.OverloadProtection,Winncom" preCondition="managedHandler" />
<add name="Rewrite" type="Winncom.Classes.HttpModules.Rewrite,Winncom" preCondition="managedHandler" />
<add name="HttpCompression" type="Winncom.Classes.HttpModules.HttpCompression,Winncom" preCondition="managedHandler" />
</modules>
<handlers>
<remove name="UrlRoutingHandler" />
<add name="PageHandlerFactory-ISAPI-2.0-html" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
<add name="*.aspx_*" path="*.aspx" verb="*" type="Winncom.Classes.Service.HandlerDispatcher" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="*/cjpegimage.aspx_*" path="*/cjpegimage.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode,runtimeVersionv2.0" />
<add name="*/webpages/*.html_*" path="*/webpages/*.html" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode,runtimeVersionv2.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Any ideas would be nice. Thanks!
Try adding this to your handlers section in the web.config
<add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>