Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

Thursday, October 02, 2014

Web.config and config file for every project in solution

Suppose a given project solution: core, data access layer and several "plugin" modules. In order to prevent changes in the core all configurations was moved to web.config. Also we would like that every module will use a dedicated config file because a "plugin" can be added and/or removed.

First solution:
In web.config file in the section "appSettings" available attribute "file" for moving segment of web config to another file. It's nice but we need more then one config file and therefore required additional configurations.Create "sectionGroup":

  1. <configuration>
  2.   <configSections>
  3.     <sectionGroup name="Plugins">
  4.         <section name="Module1" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  5.         <section name="Module2" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  6.     </sectionGroup>
  7.   </configSections>
  8. .....


Module1 and Module2 this is a names of our plugins. Create configuration section for group and define key for path of module config file in every named section:


  1.   <Plugins>
  2.     <Module1>
  3.       <add key="ConfigFile" value="App1.config"/>
  4.     </Module1>
  5.     <Module2>
  6.       <add key="ConfigFile" value="App2.config"/>
  7.     </Module2>
  8.   </Plugins>
  9.   

Create 2 new config files "App1.config" and "App2.config". In the properties of files change  "Copy to Output Directory" to "Copy always". The content of module config file look like this one:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <add key="AnyKey" value="Bla-Bla-Bla"/>
  5.     <add key="AnyKey2" value="Bla-Bla-Bla"/>
  6.   </appSettings>
  7. </configuration>

An using code:

  1. class Test
  2. {
  3.     private static readonly Configuration config = ConfigurationManager.OpenMappedExeConfiguration(
  4.         //Get config file
  5.         new ExeConfigurationFileMap()
  6.         {                                                                              //Web.config part   //File name                                         
  7.             ExeConfigFilename = ((NameValueCollection)ConfigurationManager.GetSection("Plugins/Module1"))["ConfigFile"]
  8.         },
  9.         ConfigurationUserLevel.None);
  10.  
  11.     private void Foo()
  12.     {
  13.         var value = config.AppSettings.Settings["AnyKey"].Value;
  14.         Console.WriteLine(value);
  15.     }
  16. }


Second solution:
Add  new section "Plugin". We are use the type DictionarySectionHandler in order to get values as Dictionary:
  1. <configuration>
  2.   <configSections>
  3.     <section name="Plugin" type="System.Configuration.DictionarySectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  4. </configSections>

Add values:

  1. <Plugin>
  2.     <add key="ConfigFileOfModule1" value="App1.config"/>
  3.     <add key="ConfigFileOfModule2" value="App2.config"/>
  4. </Plugin>

Create 2 new config files "App1.config" and "App2.config". In the properties of files change  "Copy to Output Directory" to "Copy always". The content of module config file look like this one:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <add key="AnyKey" value="Bla-Bla-Bla"/>
  5.     <add key="AnyKey2" value="Bla-Bla-Bla"/>
  6.   </appSettings>
  7. </configuration>

An using code:

  1. private static readonly IDictionary section = (IDictionary)ConfigurationManager.GetSection("Plugin");
  2. private static readonly  System.Configuration.Configuration config =
  3.     ConfigurationManager.OpenMappedExeConfiguration(
  4.                         new ExeConfigurationFileMap()
  5.                         {
  6.                             ExeConfigFilename = section["ConfigFileOfModule1"].ToString()
  7.                         }, ConfigurationUserLevel.None);
  8. private void Foo()
  9. {
  10.     var value = config.AppSettings.Settings["AnyKey"].Value;
  11. }



Enjoy!





Tuesday, November 08, 2011

Installing and Running IIS and Apache Server Together

We working on project that include web application based on python and several application based on IIS (as WCF , Web application, web site ant etc'). "Python" application use port 80 therefore we cannot use same port in IIS application. HERE was explained solution that based on 2 IP addresses.

p.s. One more note: you must run command prompt as administrator.

Tuesday, April 08, 2008

VS 2005 Intellisense in web.config files stop work

Now one annoying gotcha:

There is one gotcha to be aware of, though, that can sometimes cause intellisense for the web.config file to stop working in the IDE. This happens when a default namespace is added to the root <configuration> element. For example, like so:

<configuration xmlns=
"http://schemas.microsoft.com/.NetConfiguration/v2.0">





This doesn’t cause any runtime problems – but it does stop intellisense completion happening for the built-in .NET XML elements in the web.config file.

The bad news is that the built-in web admin tool (launched via the WebSite->ASP.NET Configuration menu item in VS 2005 and Visual Web Developer) always adds this xmlns namespace when it launches – so if you use this tool to manage users/roles you’ll end up having it added to your web.config file for you.

How to fix this gotcha:

To get intellisense back when you are editing the web.config file in the IDE, just delete the xmlns reference and have the root configuration element look like so:

<configuration>



Everything will then work fine again.


via


Thursday, March 27, 2008

HttpWebRequest over SSL

public static bool
AcceptAllCertificatePolicy(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}

The returned value determines whether the specified certificate is accepted for authentication.

Then set:

ServicePointManager.ServerCertificateValidationCallback
+= AcceptAllCertificatePolicy;

From here



Monday, January 28, 2008

The Chart free generation for Web Application from Google

Google Provided addition tool for Web developers  - The Google Chart API.

You can create a charts in very simple way - build necessary URL and will receive chart in one of 5 types (Line, Bar, Pie, Venn or Scatter).

A simple "pie" for example:

URL = "http://chart.apis.google.com/chart?cht=p3&chco;=4C8ED6&chs;=250x120&chl=Sun|Mon|Tue|Wed|Thu|Fri|Sat&chd;=s:ABCDEFG"

and a result:

 

 

In your control next chart parameters: Data, Type, Colors, Labels, Style, Character mappings and several optional parameters.

To Home Page click HERE

Sunday, December 23, 2007

What is the difference between URL and URI?

A URL is the address of some resource on the web, which means that normally you type the address into a browser and you get something back. There are other type of resources than web pages, but that's the easiest conceptually. The browser goes out somewhere on the internet and accesses something.

A URI is just a unique string that uniquely identifies something, commonly a namespace. Sometimes they look like a URL that you could type into the address bar of your web browser, but it doesn't have to point to any physical resource on the web.

URI is the more generic term, and a URL is a particular type of URI in that a URL has to uniquely identify some resource on the web.

Via .Net Tip of The Day

Sunday, October 21, 2007

Listas - new feature from Microsoft

At Live Labs, we are always experimenting with new ideas that we think will be useful.  Today we are releasing our latest technology preview:

Listas (http://listas.labs.live.com)

Listas is a tool for the creation, management and sharing of lists, notes, favorites, and more. It allows you to quickly and easily edit lists, share them with others for reading or wiki-style editing, and discover the public lists of other users.  We encourage you to try using it for meeting notes, bookmarks, shopping lists, to plan a night out, or whatever other creative ways you can think of....

kick it on DotNetKicks.com

Monday, July 16, 2007

Review - Google Applications for your Domain.

Google ApplicationsShort review of google apps for domains after a using during 2 weeks. General glimpse,positive and negavtive characteristics and other. To reading of the full review click here.

Tuesday, February 20, 2007

Personal Wallpapers and Screensavers for mobile phones

For the first time, the Internet site for a personal wallpapars and screensavers for mobile phones. Absolutely free.

Free mobile phone wallpaper generator

Example:
Personalized wallpapers and screensavers for mobile phones

Sunday, June 04, 2006

Buttons

Here extremely simple service for creation of buttons "On the fly"...
http://www.buttonator.com/

Tuesday, April 25, 2006

Google advanced operators

Target/Task

links

Uses operators

What Google site writes about blog?

site:google.com inanchor:blog

site: inanchor:

Find car BMW in UK

Results from all word: BMW

Result from UK and other link:

BMW UK

Results from UK only:

inurl:co.uk intitle:BMW

Inurl:

Find info about bugs

Any bugs: Bugs

Any bugs except of computer bugs: Bugs -computer

Exclusion

Understand the DOT.NET dataset class structure

dataset

Google images

What Blog is?

Define: blog

define

Find info about mobile/cellular phones

Intitle: phones intitle:~mobile

Synonyms(~)

Find PowerPoint presentation about cars/auto

~car filetype:ppt

Synonyms(~), filetype

Find any installation guide in flash

"installation guide" filetype:swf

Exact match(""), filetype

Find middle Vladimir Putin name

"Vladimir * Putin"

Asteric(*)

Effect of incomming links

Click here (Adobe, XE, Macromedia)


List of operators:

Intitle,allintitle


Inurl, allinurl


Filetype


Allintext


Site


Link


Inanchor


Daterange


Cache


Info


Related


Phonebook


Rphonebook


Bphonebook


Author


Group


define


Msgid


Insubject


Stocks