Introduction:
Here i will explain How to store custom data in web.config?
Description:
Previous article i will explain Get Your Desktop Details of your Windows Operating System in ASP.Net and Creating a Custom Data Adapter in Asp.Net and How to search through GridView records in asp.net using jQuery. Now today i will explain How to store custom data in web.config.
Web.Config:
....
CS:
public class DataProviders : IConfigurationSectionHandler { private static bool _initialized; public static List_providers; public object Create(object parent, object configContext, XmlNode section) { XmlNodeList providers = section.SelectNodes("Provider"); _providers = new List (); foreach (XmlNode provider in providers) { _providers.Add(new Provider { Type = provider.Attributes["type"].Value, Alias = provider.Attributes["alias"].Value, }); } return null; } public static void Init() { if (!_initialized) { ConfigurationManager.GetSection("DataProviders"); _initialized = true; } } public static IEnumerable GetData(string dataProviderAlias) { return _providers.Where(p => p.Alias == dataProviderAlias); } } public class Provider { public string Type { get; set; } public string Alias { get; set; } }
Global:
public class Global : System.Web.HttpApplication { void Application_BeginRequest(object sender, EventArgs e) { DataProviders.Init(); } }
Usage:
var providers = DataProviders.GetData("FirstProvider").ToList();
0 comments :
Post a Comment