Sunday, September 20, 2009

CSS - height loose when all elements are float in a <div> block

When all the elements in a <div> block are float, Firefox can't keep the height of block, in this example the border appears just on top side:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <meta http-equiv="Content-Type"
   content="text/html; charset=iso-8859-1">

   <title>height loose</title>

</head>

<body>
   <div style="margin:auto;width:350px;border:5px solid #CCC;">
      <img style="float:left;margin-top:0.5em" src="Design.jpg" />
      <span style="float:right;margin-top:1em; margin-right:0.5em">
      <b>Development</b>
      </span>
   </div>
</body>
</html>


To solve the problem, it's necessary to explicitly set the height of block and it's better to use em for height size unit cuz of covering different font size of contents:


   <style type="text/css">
      #hdr {
         height: 4em;
      }
   </style>

   <div id="hdr" style="margin:auto;width:350px;border:5px solid #CCC;">
   ...
   </div>


IE doesn't show such a behavior, it's yet another place that coder should consider cross browser development techniques.
Share/Bookmark

Saturday, September 19, 2009

ASP.NET - URL Mapping in Web.config

The URL mapping feature uses configuration information stored in web.config to remap incoming requests to a different URL. The remapping occurs prior to any other processing for the inbound request. Although the sample below demonstrates remapping a page request, any arbitrary file type can have its request remapped to a different URL.

Imagine some body kept the URL of your web site in their bookmarks and you want to change the pages and structure of your site so that it affects the URLs, then you need to redirect the old ones to new correct destination, it works if you consider URL mapping.

The URL mapping feature uses to redirect incoming requests to a different URL. Prior to any other processing for the incoming request the remapping happens.

URL Mapping stores in web.config file, inside <system.web> tag, it's possible to add elements in <urlMappings>. In <add> tag there is url attribute which points to exact value of incoming url and mappedUrl attribute keeps value of rewritten url which is the exact redirected destination.


<configuration>
   <system.web>
      <urlMappings>
         <add url="~/LCDs.aspx" mappedUrl="~/prds.aspx?prdCat=lcd" />
         <add url="~/DVDs.aspx" mappedUrl="~/prds.aspx?prdCat=dvd" />
         <add url="~/MP3s.aspx" mappedUrl="~/prds.aspx?prdCat=mp3" />
      </urlMappings>
   </system.web>
</configuration>


With URL mapping, the redirection works the same as the Server.Transfer() method, and browser will still show the original incoming request URL, not the mapped URL.

The Request.RawUrl property returns the original request URL.
The Request.Path property reflects the result of mapped URL.
Request.QueryString["yourQueryStringElement"] also return the result from the mapped URL.

If we have a site map provider in our web page, it first try to use the original request URL when looking for the node in the site map which is provided by Request.RawUrl, if it doesn't find the matched record, it uses the Request.Path property.

Incomming Request --->
   Mapping available in Web.config?
      --- YES ---> Use mappedUrl path --->
                                                      [Render requested path]
      --- NO --------------------------------->
Share/Bookmark

Thursday, September 17, 2009

Free Web Hosting - Web Hosting Company Reviews

Free Web Hosting list by ABOUT.com

Web Hosting Company Reviews
The data is based on reviews by people who have used the web hosting services from the hosting companies.
Share/Bookmark

10 Best and Worst Web Hosting Providers!

Something interesting from ABOUT.com, at least it worth to take a look at the following lists, I don't want to say that I'm agree or disagree with the result which ABOUT.com collected, it's just interesting.

10 Best Web Hosting Providers
As Rated by About.com Readers

10 Worst Web Hosting Providers
As Rated by About.com Readers

Last updated 21 April 2009
Share/Bookmark

Friday, September 11, 2009

ASP.NET - EventLog Class - Custom logs


It's a good idea to log errors and unexpected conditions in event log. But if you want to record user actions or other data which repeats a lot and consume considerable amount of space, the Event Log is not a good choice and may be it's better to log it in database tables or XML files, because Event log uses disk space and takes processor time and it will affect overall performance of machine and our application.

EventLog class in System.Diagnostics namespace allows us to utilize related functions in .NET, on the other hand, it's a good practice to make a custom errors log and record messages related to our application there. Then Event Viewer will collect messages in an individual place which allows us to keep track of them easily. the following sample code implements custom event logging idea.

try
{
// ...
// you code here
// ...
}
catch (Exception ex)
{
string logName = "myWebAppEventLog";
if (!EventLog.SourceExists(logName))
{
EventSourceCreationData escd =
new EventSourceCreationData("myWebAppSrc", logName);
escd.MachineName = System.Environment.MachineName;
EventLog.CreateEventSource(escd);
}
EventLog evntLog = new EventLog(logName);
evntLog.Source = "myWebApp";
evntLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}


To find more you can take a look at following URLs and or search online.
- EventLog Class
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog%28VS.71%29.aspx

- How to manage event logs using Visual C# .NET or Visual C# 2005
http://support.microsoft.com/kb/815314

- Security Ramifications of Event Logs
http://msdn.microsoft.com/en-us/library/4xz6w79h%28VS.71%29.aspx
Share/Bookmark

Thursday, September 3, 2009

TypeDescriptor.GetConverter - unified way of converting types of values to other types

...
string[] brdrStyleAry = Enum.GetNames(typeof(BorderStyle));
rbtnBrdr.DataSource = brdrStyleAry;
rbtnBrdr.DataBind();
...
TypeConverter objCnvrtr =
TypeDescriptor.GetConverter(typeof(BorderStyle));
pnlCard.BorderStyle =
(BorderStyle) objCnvrtr.ConvertFromString(rbtnBrdr.SelectedItem.Text);

Share/Bookmark