xdt:transform with similar attributes - xdt-transform

I have a configuration file that contains WCF settings:
<host>
<add baseAddress="net.tcp://myaddress.com:12345/MyService"/>
<add baseAddress="net.tcp://anotheraddress:67890/MyOtherService"/>
</host>
The 'add' element only has a baseAddress attribute and so I can't use the Match locator. How would one approach transforming multiple elements like in my example?

What I ended up doing was moving the xdt:Transform="Replace" to the parent node like:
<host xdt:Transform="Replace">
<add baseAddress="net.tcp://myaddress.com:12345/MyService"/>
<add baseAddress="net.tcp://anotheraddress:67890/MyOtherService"/>
</host>

Related

How to specify the networkCredential param using xml in Serilog.Sinks.Email

I'm trying to setup this sink Serilog.Sinks.Email using xml
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Warning" />
<add key="serilog:write-to:Email.from" value="email-from" />
<add key="serilog:write-to:Email.to" value="email-to" />
<add key="serilog:write-to:Email.mailServer" value="mail-server" />
<add key="serilog:write-to:Email.outputTemplate" value="tmpl" />
<add key="serilog:write-to:Email.networkCredential" value="???" />
since networkCredential implements ICredentialsByHost, is possible to specify it using xml?
This is a limitation in the config for the email sink, and/or appsettings support at the moment.

<IndexUserFields> fields haven't been indexed

I'm working on an Umbraco project.
I'm using a StandardAnalyzer indexer and I've just added an ArabicAnalyzer indexer.
The fields under <IndexUserFields> haven't been indexed.
part of my ExamineIndex.config file:
<IndexSet SetName="ArabicIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Arabic/" >
<IndexAttributeFields>
<add Name="id" />
<add Name="sortOrder"/>
<add Name="nodeName" EnableSorting="true"/>
</IndexAttributeFields>
<IndexUserFields>
<add Name="_AllContents"/>
<add Name="cityName"/>
<add Name="countryName"/>
</IndexUserFields>
<IncludeNodeTypes>
<add Name="Country" />
<add Name="DestinationInfoTopic" />
<add Name="Article" />
</IncludeNodeTypes>
</IndexSet>
All <IndexAttributeFields> fields are indexed, but <IndexUserFields> aren't, BTW the same fields are indexed using StandardAnalyzer.
Do I need to do something extra in order to index these fields?
After hours of digging finally I found an answer to my problem.
Due to our ArabicAnalyzer usage we must add the indexSet name to the Indexer provider:
<add name="ArabicIndexer"
type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
supportUnpublished="false"
supportProtected="false"
interval="15"
analyzer="Lucene.Net.Analysis.AR.ArabicAnalyzer, Lucene.Net.Contrib.Analyzers"
indexSet="ArabicIndexSet" />

Setting up SimpleMembership in MVC4

I am reading that in MVC4 to set up simple membership I should do this step:
In the AppSettings include a line:
<add key="enableSimpleMembership" value="true" />
However when I look at the samples generated from the templates they only have:
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
So why do I keep reading it's necessary to set the enableSimpleMembership key?
By default the SimpleMembershipProvider is enabled when you create a new ASP.NET MVC 4 application. But some hosting providers might disable it by overriding this setting in a higher level web.config.
Quote from an article about SimpleMembership:
If you see an error that tells you that a property must be an
instance of ExtendedMembershipProvider, the site might not be
configured to use the ASP.NET Web Pages membership system
(SimpleMembership). This can sometimes occur if a hosting provider's
server is configured differently than your local server. To fix this,
add the following element to the site's Web.config file:
<appSettings>
<add key="enableSimpleMembership" value="true" />
</appSettings>
This setting is used by the WebMatrix.WebData.PreApplicationStartCode method which executes automatically when your site runs and will use the value of this setting to enable the simple membership provider.
Actually configuring the SimpleMembershipProvider explicitly is what I would recommend you:
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear/>
<add name="SimpleMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<providers>
<clear/>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
</providers>
</roleManager>
Now, there's no room for confusion anymore. Both the membership and role providers are configured explicitly.

ASP.NET Views: Avoiding using <%# Assembly... in every .aspx

Virtually every .aspx page I have in my web site needs to have this at its top to function correctly:
<%# Assembly Name="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
Is there anyway I can avoid having to declare this in the .aspx view for every page? Isn't there some way I can declare this globally for all .aspx views? Maybe something in the web.config?
Add it to assemblies
<assemblies>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
The #Assembly directive correspond to assemblies tag in web.config not namespace tag. Check MSDN reference
You can declare it in web.config in the assemblies section, like this:
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=3.0.0.0 ... "/>
</assemblies>
</compilation>
</system.web>
However, according to the MSDN docs:
Assemblies that reside in your Web application's \Bin directory are automatically linked to ASP.NET files within that application. Such assemblies do not require the # Assembly directive. You can disable this functionality by removing the following line from the section of your application's Web.config file:
<add assembly="*"/>
As others have pointed out, you can declare this in the web.config pages section.
Another alternative (if its available to you) is to use the new Razor View engine. It not only removes this type of code, but also provides cleaner, overall syntax. Of course, I realize this may not be a viable solution as you may be limited by your current technology/customer needs/etc.
An example of what you may see at the top of a Razor page is shown here:
#model Some.StronglyTyped.Model
#using Other.Libraries.To.Import
#{
ViewBag.Title = "Specific Page Title";
}
Put it in the Web.config as a global namespace. It will be available to all your pages there.
<system.web>
<pages>
<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>

Explicitly changing a connection string for MembershipProvider

I am using the following provider to look up users from ADAM. I would be able to like to change the connection string dynamically depending on the type of user. How can I achiev this?
<add name="con1" connectionString="LDAP://con1.url" />
<add name="con2" connectionString="LDAP://con2.url" />
<providers>
<add name="ConnectionProvider" connectionStringName="con1" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" attributeMapUsername="userPrincipalName" enableSearchMethods="true" />
</providers>
You can get specific sections of the .config by using the ConfigurationManager.GetSection() method (System.Configuration namespace). From here, just apply the logic and select the connection string you want.

Resources