Insight of Web Technology & Web Page Rendering.

As a web developer every one must know the way web works and thus will be able to develop a better solution for the client. This post will give a basic insight to all web developers to understand the concepts behind each technology.

Basic things that is required for a web application is..
1) Web Pages
2) Client
3) Web Server

Let us inspect each entity to get a clear idea.
Webpages can be static or dynamic. Static web pages are the ones which will contain all the HTML markup hardcoded in the page and when requested server can directly serve the page to the client with out any processing. When it comes to Dynamic sites it is different.

As any web site can be opened in the compatible browser and browsers are just the rendering engines of the web pages served from server after a request we will not do any thing different in applications developed in different technolgies, thus we will not concentrate much on Client(Browser) in this blog post.

Web pages can be developed in any of the technologies like HTML, ASP.Net, JSP, PHP. Each uses different types of programming model and launguage is different from one to one but still the out put what we see in the client would be more or less same because the Parsers of the engines and modules which handles the requests will make a difference here. For ex: The ASP.Net control placed in the ASP.Net will be understood by ASP.Net parsing engine and accordingly parses the control to corresponding HTML with information and send it to the client. Similarly the PHP Isapi DLL and the Java engine works to render the HTML Content accordingly.

Many developers thinks that ASP.Net is completely different from java and PHP, In reality yes with respect to coding and background engine but with functionality and for end user it is same. All its needed to be understood is the engines rendering capability and CSS,Javascript. For Ex. If you look at the Treeview in ASP.Net and the way it rendered by Viewing source in browser, you will find a whole bunch of HTML,Javascript and Styles. So that Treeview what we place in Web Page when it comes back to browser it will be rendered as div’s, tables and other HTML Tags.

Examine the way a control in rendered in any technology and that’s it you will be able to develop applications in any of the web technology and also you will be able to leverage any web framework.

Posted in ASP.Net | Tagged , , | Leave a comment

Silverlight configuration values from an external file.

As every silverlight developer knows silverlight stores its own configuration file inside the .XAP file. There falls a requirement and need for the modifications of these configuration files because of different environments and configuration due to different SDLC’s.

Each time we change the environment and there is some modifications in this config we may need to recompile the application according to the need, which will drive us into several unforeseen problems due to differences in environments.One can avoid this problem in 2 ways.

First one is to rename the .XAP file extension to .ZIP, extract the content, modify the config and zip it back to rename back to .XAP.

Above approach is useful when you dont have to pass your application through multiple dev & deployment environments. But this will be problamatic when you develop a solution for enterprise where you application should be deployed for multiple entities and different configurations. Second approach eliminates this by simplifying the process by keeping an additional flat or xml file with all configurations in it, which is easy to modify and deploy to the location.

Lets look at how we can do this: I use XML file generally as configuration file because of XML support in the .Net frameowrk. We will see how we can access an XML config file to silverlight and thus load the configuration information to SL application variables.

Config.xml
<?

xml version="1.0" encoding="utf-8" ?><MySLAppConfig><config key="key1">xyz</config><config key="key2">xyz</config><config key="key3">xyz</config><config key="key4">xyz</config><config key="key5">xyz</config><MySLAppConfig>
Copy this config file into the folder where the .XAP file will be placed.

In the code declare the properties which will be used by the application and should be loaded from this config file.

Create the Properties in App.xaml.cs
private string _Key1;
public string Key1 { get { return _Key1; } set { _Key1 = value; } }
private string _Key2;
public string Key2 { get { return _Key2; } set { _Key2 = value; } }
private string _Key3;
public string Key3 { get { return _Key3; } set { _Key3 = value; } }
private string _Key4;
public string Key4 { get { return _Key4; } set { _Key4 = value; } }
private string _Key5;
public string Key5 { get { return _Key5; } set { _Key5 = value; } }

In the App.xaml use the webclient and download the xml file from location as a string.
Uri url = new Uri("Config.xml", UriKind.Relative);
WebClient client = new WebClient();
client.DownloadStringAsync(url);
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);

Access the values from the event handler code.
try
{
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
if (!reader.IsEmptyElement)
{
while (reader.Read())
{
if (reader.MoveToAttribute("key"))
{
switch (reader.Value.ToString())
{
case "Key1":
reader.MoveToElement();
Key1 = reader.ReadElementContentAsString();
break;
case "Key2":
reader.MoveToElement();
Key2 = reader.ReadElementContentAsString();
break;
case "Key3":
reader.MoveToElement();
Key3 = reader.ReadElementContentAsString();
break;
case "Key4":
reader.MoveToElement();
Key4 = reader.ReadElementContentAsString();
break;
case "Key5":
reader.MoveToElement();
Key5 = reader.ReadElementContentAsString();
break;
}
}
}
}
else
{
MessageBox.Show("Unable to Find configuration Params");
}
}
catch
{
MessageBox.Show("Configuration file not found or unable to access it.", "Config error", MessageBoxButton.OK);
}

These property values can be accessed across the application in the following way.
App oApp = Application.Current;
string val1 = oApp.Key1;

This way we have got the flexibility to change the configuration easily and using it in the application.

Happy Coding. :)

Posted in Silverlight, Technology | Tagged , , | Leave a comment