Web.config partial search and replace - xdt-transform

I have App.config file in C# application.
I want to partially replace all Keys matching ".UAT" with ".PROD" using xdt tranform.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="MyParam1.UAT" value="param1"/>
<add key="MyParam2.UAT" value="param2"/>
<add key="MyParam2.UAT" value="param3"/>
</appSettings>
</configuration>
Here is the output I want
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="MyParam1.PROD" value="param1"/>
<add key="MyParam2.PROD" value="param2"/>
<add key="MyParam2.PROD" value="param3"/>
</appSettings>
</configuration>
So far I've tried this using CustomTransform but it replaces only one element instead of all element. How can i get this to replace all elements
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add xdt:Locator="Condition(contains(#key, '.UAT'))" xdt:Transform="AttributeRegexReplace(Attribute='key', Pattern='.UAT',Replacement='.PROD')" />
</appSettings>
</configuration>

I found the answer here where I had to replace the Apply method with this method that iterates over all attributes
protected override void Apply()
{
foreach (XmlNode target in this.TargetNodes)
{
foreach (XmlAttribute att in target.Attributes)
{
if (string.Compare(att.Name, this.AttributeName, StringComparison.InvariantCultureIgnoreCase) == 0)
{ // get current value, perform the Regex
att.Value = Regex.Replace(att.Value, this.Pattern, this.Replacement);
}
}
}
}

Related

Can't upload large files ASP.NET / IIS 6.2

I can not upload large files. My page is base in ASP.NET.
In IIS I have 2 sites;
-1 for web service
-1 for web page
I try many ways that I found, but no work
Web service config;
////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
...
</appSettings>
<connectionStrings>
...
</connectionStrings>
<system.web>
<httpRuntime maxRequestLength="50097151" />
<compilation debug="true" targetFramework="4.5.2" />
<authentication mode="Windows" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
</system.web>
</configuration>
////////////////////////////
////////////////////////////
Web page config;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\....exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true">
<environmentVariables />
</aspNetCore>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="50741824" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
I expect upload large files, but the actual is that I only can upload small files.
[HttpPost]
[DisableRequestSizeLimit]
public ActionResult uplo(string filename, string base64)
{
if (base64 != null && filename != null)
{
Models.filemodel archmod = new Models.filemodel ();
var xxx= archmod .namefunction(filename, base64);
return new EmptyResult();
}
return new EmptyResult();
}
It works with [DisableRequestSizeLimit] tag !!!

Exception occurred while initializing the database. Login failed for user on re-creation after deletion

On the first run my program creates the database and log file correctly in the user's folder.
If I then delete the database and log file and run the program again I get an error.
using System;
using blocks6.Module.BusinessObjects;
namespace BlocksConsole
{
class Program
{
static void Main(string[] args)
{
try
{
AddToTable();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static void AddToTable()
{
using (var db = new blocks6DbContext())
{
var inf = new ModuleInfo();
db.ModulesInfo.Add(inf);
db.SaveChanges();
}
Console.WriteLine("Fin");
}
}
}
and
using System.Data.Entity;
namespace blocks6.Module.BusinessObjects
{
public class blocks6DbContext : DbContext
{
public blocks6DbContext()
: base("name=ConnectionString")
{
// Database.SetInitializer(new DbInitializer()); uncommenting makes no difference
}
public DbSet<ModuleInfo> ModulesInfo { get; set; }
}
public class DbInitializer : CreateDatabaseIfNotExists<blocks6DbContext>
{
}
public class ModuleInfo
{
public int Id { get; set; }
}
}
app.config is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="ConnectionString" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Data Source=(localdb)\mssqllocaldb;Initial Catalog=blocksConsole" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
The project file is
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{477EDA75-B7F0-4D45-866F-0AB92CE38783}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>BlocksConsole</RootNamespace>
<AssemblyName>BlocksConsole</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BlocksDbContext.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EntityFramework">
<Version>6.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
My Win10 OS is Version 1809 Build 17763.194
Rebooting does not help.
[Update]
I created a new console program on a different computer running VS 15.8.1
The program locks up on the line
db.ModulesInfo.Add(inf);
When I upgraded to 15.9.4 the lock up ceased. However the error re-creating the database repeats on this computer too.
Winver on the second computer shows 1803 17134.471
Emptying the recycle bin does not help.
It turns out that the deleted database still shows as a node in SQL Server Object Explorer ( inside Visual Studio)
If I delete it
then the program runs successfully to re-create the database.

How to create own WebViewPage in mvc?

I want to create own WebViewPage class so that i have created my class which is shown below
public abstract class iBlueWebViewPage<TModel>:WebViewPage
{
protected iBlueWebViewPage()
{
}
public HtmlHelper<TModel> iBlue { get; set; }
}
for example if we want text box in mvc we can code #html.TextBox("Name")
like that i need #iBlue.TextBox("Name") instead of #html
How can i achieve that ?
Thanks in advance..
You should change base type of pages, from web configuration (pages element)
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,
System.Web.Mvc, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="MyNamespace.iBlueWebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
More detailed reading at Phil Haack's article (example is taken from there)

MVC3 Could not find schema information for the element 'entityFramework' when using EF 5.0

I found the following messages in my we.config file after looking for a couple of minutes to see why my database was not seeding.
The complete message list is as follows:
Message 1 Could not find schema information for the element 'entityFramework'.
Message 2 Could not find schema information for the element 'defaultConnectionFactory'.
Message 3 Could not find schema information for the at'type'.
Now I am extremely new to MVC, and this is my first application that I have ever built. I want to utilize the Code First Technologies available to create the database from my models that I have built.
Here is an Example of a model I Created:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
namespace TNTMVC.Models.UECDECZA.BaseTables
{
public class Actions
{
[Key]
public int ActionID { get; set; }
[Timestamp]
public DateTime ActionDateCreated { get; set; }
[Required]
[DefaultValue(true)]
public bool ActionActive { get; set; }
[Required]
public string ActionName { get; set; }
[Required]
[DefaultValue(true)]
public bool ActionRequiresComponents { get; set; }
[Required]
[DefaultValue(1000)]
public int ActionListOrder { get; set; }
}
}
Then I created my DB Context Class which looks like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using TNTMVC.Models.UECDECZA.BaseTables;
using TNTMVC.Models.UECDECZA.DataTables;
namespace TNTMVC.Models.UECDECZA
{
public class UecdeczaContext : DbContext
{
public DbSet<Actions> Actions { get; set; }
public DbSet<Application> Application { get; set; }
public DbSet<Area> Area { get; set; }
}
}
And here is my Web.Config file:
<?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=152368
-->
<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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="UecdeczaContext" connectionString="Data Source=.\SQLExpress;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="System.Data.Entity" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
This is suppose to be a successful model implementation right? But it doesn't seem to work at all. It's not seeding my Database and it's not working :(
I have also Asked the same Question on ASP forumns: My ASP Forum Question
You don't seem to have an initializer (other than the default one) that is calling a Seed() method. See Julia Lerman's blog post on seeding for more info. You need something like:
public class UecdeczaInitializer : DropCreateDatabaseIfModelChanges<UecdeczaContext >
{
protected override void Seed(UecdeczaContext context)
{
new List<Actions>
{
new Actions
{
ActionName = "My action name"
}
}
}.ForEach(b => context.Blogs.Add(b));
base.Seed(context); }
}
You might need to stick more properties in there to seed your Actions entities, but that's the basic idea.

Problem with HtmlHelper and MVC not seeing my new method

I tried to create this HtmlHelper method:
namespace Power.WebUx.Helpers
{
public static class HtmlHelperExtensions
{
public static MvcHtmlString SelectedIfMatch(this HtmlHelper helper, string actual, string expected)
{
if (expected == actual)
{
return new MvcHtmlString("<option selected=\"selected\" value=\"" + actual + "\"" + actual + "</option>");
}
else
{
return new MvcHtmlString("<option value=\"" + actual + "\"" + actual + "</option>");
}
}
I added the Power.WebUx.Helpers line to my web.config:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Power.WebUx.Helpers" />
</namespaces>
</pages>
However when I try to use the extension I get an error message saying that System.Web.Mvc.HtmlHelper does not contain a definition for SelectedIfMatch
Does the code I am trying to run look right or am I missing something?
Hope someone can see something obvious.
thanks
Jon Wylie
Import the namespace into your view to use any extension methods in that namespace
<%# Import Namespace =
"Power.WebUx.Helpers" %>
Make sure you're modifying the top level web.config file(instead of the one in the views folder), then close and open the files where you're trying to use the helper

Resources