I have one project for publishing two separate websites on different servers. Both websites is in different languages (En and tr).
For web-deploy I want to change appsettings for different environments for Debug and Release (For both websites).
I added config files for transformations like this:
Appsetting in main Web.config:
<add key="WebsiteMainCulture" value="en-US"/>
The code in transformation files are accordingly like this:
<appSettings>
<add key="WebsiteMainCulture" value="TR"
xdt:Locator="Match(key)" xdt:Transform="Replace"/>
</appSettings>
I selected Web.TR.Debug.config and ran project, But I always get 'en-US' as WebsiteMainCulture.
string website_main_culture = ConfigurationManager.AppSettings["WebsiteMainCulture"].ToString(); // always en-US
Please help. Is there any better approach suggested for same environment?
Thanks!
I got the solution for the problems I asked, also related to my previous question here:
https://stackoverflow.com/questions/30612865/selecting-correct-seed-method-for-particular-language
I just added config transformation files by right clicking, to relevant publish(web deploy) files.Then added desired values to keys. And it worked.
Here are config transformation file auto generated.
Related
I discovered something unexpected with my ASP.NET WebApp (Visual 2017 .NET Framework 4.6.1) in a production environment.
I have a model with a property StringDato, which is a STRING following the pattern dd.mm.yyyy hh.mm.ss (the german/european format).
Having faced some issues for parsing, I decided to work with strings for my dates, so there is no a single part of my code where I refer to a DateTime object.
In my development and testing environments (2 different IIS servers), StringDato is displayed as it should be. But in the production environment (a third IIS server) it always shows US formatted.
For example, 23.09.2017 17.45.00 will become 9/23/2017 5:45:00 PM. This happens no matter what the browser is (IE/Edge/Chrome).
The browser is german/european configured, and so is the user's system. The only thing I don't know about yet is how my production server is configured.
I'm trying to get the logic here. Does it make sense to assume the server could "recognize" a string as a date because of its pattern, display it as a date, and format it according to it's config and not the user's settings? What else can I look at to fix this?
It´s simple. Keep Invariant Culture Info on Web.Config:
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
<globalization uiCulture="de" culture="de-DE" />
</system.web>
I need to log events in Json format using Serilog. I want to use RollingFileSink.
According to the following link, we cannot specify TextFormatter in App.config file.
How to specify JsonFormatter in Web.config for SeriLog?
Is is possible to specify all other configurations like file path in app.config and then add textformatter as JsonFormatter in code while initialing the logger?
Just using plain settings works well for this, e.g.:
<add key="filePath" value="C:..." />
And:
WriteTo.RollingFile(..., ConfigurationManager.AppSettings["filePath"])
I have a web application and I need to provide its users the option to switch login method from FormsAuth to WindowsAuth. I managed to change the web.config file via code:
Configuration config = WebConfigurationManager.OpenWebConfiguration(Url.Content("~"));
AuthenticationSection auth = ((AuthenticationSection)(config.SectionGroups["system.web"].Sections["authentication"]));
auth.Mode = AuthenticationMode.Windows; // Or Forms if I want to.
config.Save();
But the problem is, when I use FormsAuth, I need the Anonymouse Authentication option to be turned on, and when I use WinAuth, I need it to be off. And I just cannot find the way to change that option via code.
Everything on the internet says to do this:
<security>
<authentication>
<anonymousAuthentication enabled="false/true" />
</authentication>
</security>
But when I insert this into my webapp's web.config it says that configuration is wrong. Than I read this might work in another config file, like appHost.config or something like that but I prefer to make changes only to my own application and not to IIS I hope you understand why.
So, how can I do that?
You are trying to update wrong section. anonymousAuthentication is part of system.webServer and not system.web. Correct configuration is
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
You can modify it using ServerManager class found in Microsoft.Web.Administration. Search for nugget package "Microsoft.Web.Administration". Once you have added reference to Microsoft.Web.Administration.dll using nugget you can modify it using code as follows:
using (ServerManager serverManager = new ServerManager())
{
Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
Microsoft.Web.Administration.ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication");
anonymousAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
}
Okay, so, turned out I could not find a way to dynamically change the auth mode, but I found pretty neat solution to the problem: I have created another web application, nested it inside the first one, had set Forms Auth mode for the first one and Windows for the nested and whenever I needed to use IIS's power to work with domain, user groups etc, I used a redirect from one to another, passing data by cookies and as url parameters.
I am using Quartz .net with an AdoJobStore jobStore. In the .config file, there is a property that is used to set the connection string:
<add key="quartz.dataSource.default.connectionString" value="Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True" />
However, I manage all my connection strings in a separate config file, so I currently need to dupplicate this connectionString information.
Is there a way to not specify the quartz.dataSource.default.connectionString in the .config file and manually set it via code, so I can get my value in my global connectionStrings config file?
It seams that it is possible to use a NameValueCollection when instanciating a StdSchedulerFactory, but I don't want to manage all settings, only the connectionstring.
In the end, they are all simply named-value pairs.
You can have "most" of them in an .xml file...then "add in" the ones you want via code.
Or have all of them in code.
See the UnitTests for the source code, and you'll see this fairly clearly.
Something like this:
NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");
config.Add("MyCodedUpKey", "MyCodedUpValue");
I would NOT put
"quartz.dataSource.default.connectionString"
in your .xml file...to avoid a collision..... Or you can write extra logic to remove and add to the
NameValueCollection .
Or take a peek here:
Check if Key Exists in NameValueCollection
Finally fix my problem by passing all the configuration attribute using code, but by parsing the quartz config to get them automatically.
And I manually add the quartz.dataSource.default.connectionString property at the end and setting the value by getting it in my global connectionStrings.config file.
The Issue
We have two sites, one domain, we want to setup a virtual directory on the domain which can access the second site.
IIS virtual directory doesn't seem to do the trick, sitecore does not seem to play nicely.
Is there a potential work around using sitecore?
The Environment
We have the following folder structure for two of our sites:
C:\Sitecore\Site1
C:\Sitecore\Site2
Site 1 and Site 2 both connect to the same web, core and master databases.
To access the cms for both sites in the browser we do:
www.mysite1.com/sitecore
From Site 1's cms we create content, layouts and templates for Site 1 and Site 2.
The Solution
What we did is in the first sites web.config we defined the site as normal:
<site name="site1" hostName="mysite1.com" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/MyItem1/" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
In the second sites web.config we defined the site slightly differently:
<site name="site2" hostName="mysite1.com" virtualFolder="/Site2" physicalFolder="/" rootPath="/sitecore/content" startItem="/MyItem2/" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
The second site we defined a virtual folder which you can notice above that was the only difference along with the obvious start item differences.
Site 1 will respond like normal. You can visit mysite1.com it will load the start item relevant for website 1.
When you visist mysite1.com/Site2/ it will load the virtual folder defined in the second site and load its relevant start item.
That is pretty much it works like a charm.
And finally #Mark Ursino thanks for your help.
To Note
You need have sitecore scalability configs enabled for any of the above to work
From what I think I understand, I think you need to make some changes in the config to set the "sub-folder site" as a virtualFolder:
<site virtualFolder="/subsite" physicalFolder="/subsite" rootPath="/sitecore/content" startItem="/MyItem/" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
Note that virtualFolder="/subsite" and physicalFolder="/subsite" point to the subfolder, but I don't think you need that physical folder really there.
Reference used.
Maybe this post will be useful http://sitecoreblog.alexshyba.com/2012/02/have-sitecorecontent-in-your-link-time.html