April 2005 - Posts
I experimented with
AJAX.Net Wrapper
for the pass 2 days and the result is great. I am creating a sample
website which I try to explore the different aspect of Ajax and see how
I can use it in different ways. Hope to get the site up soon so can
post it up here for comments.
Today, I experimented with another aspect of AJAX, from Flash.
Normally, calling aspx.net scripts from Flash is asyncronous, so we do
not really need to worry about it. However, AJAX comes into play if we
have a web page which comprises of both Flash components and HTML
counterparts (e.g. like CNet, main site HTML base and the video,etc in
Flash). In the past, if I need Flash to change contents on the
HTML page base on some server side processing, some postback will
sometimes be needed, depending on the requirements. However, postback
means that the Flash movie will have to restart. So AJAX can comes into
play in this case to solve the problem.
Will post more on this in days to come
I just realized that MIT (Massachusetts Institute of Technology) as an
Open Coursware concept where people can freely download their lectures
notes and stuff. View complete course list
here
I was reading through Jeffrey Putz's
Maximizing ASP.NET: Real World, Object-Oriented Development
today when I come across this useful piece of code snippet to prevent people from leeching your jpg files. Interesting.
using System;
using System.Web;
public class JpgHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string FileName = context.Server.MapPath(context.Request.FilePath);
if (context.Request.UrlReferrer.Host == null)
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("/no.jpg");
}
else
{
if (context.Request.UrlReferrer.Host.IndexOf("mydomain.com") > 0)
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile(FileName);
}
else
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("/no.jpg");
}
}
}
public bool IsReusable
{
get
{ return true; }
}
}
web.config
Went to clementi book store today to see see look look. I always go to
comp book store at Funan but I heard from friends that Clementi book
store sell computer books at competitive price too, so I decide to drop
by and take a look. I realise that around 40% of the books sold there
are not software related, as compared to Funan's comp book store where
around 95% are computer books. Guess I will still stick to Funan's comp
book store to find computer books, although nowadays there is actually
less needs to purchase books on software tutorials are there are many
resources/courseware on the net that is readily available. Not to
mention e-book library that is available like the one hosted on
java.net
and
safaribooks
I was thinking, with so many free online tutorials, pdf and ebook
available, what will be the future of book store be like ? (especially
book stores that sell software books). Will they still have a role in
the society in years to come? Or will they have to shift their brick
and mortar business model to the one like safaribooks. One greatest
advantage of traditional book store is of course, allowing the
customers to fully browse the books. Well, online store also allow
that, but only a few selected chapters and IMO, previewing online books
is a pain (I prefer to download the entire pdf at one go rather than
wait for 10 seconds to load each page). Maybe you guys can share your
view on bookstores here.
The next book I am look forward to is
Advanced ColdFusion MX 7 Application DevelopmentI
actually hope to take Certified Coldfusion MX 7 developer exam this
coming June, but was thinking of putting it off till the take over
between Adobe and Macromedia finishes
Guess just concentrate on 70-290 first..=)
As a follow up to my previous
post on
AJAX , it looks AJAX has been used to integrated with Flash/Flex
Read it at
MXNA Reports : Flex / Flash / AJAX Integration .
My window server 2003 crashed on Sunday night. However due to the heroic efforts from the guys from
8toInfinity,
they managed to restore it within a day. Just want to take this chance
to thanks them and maybe help them advertise for a bit, haha. Million
thanks!
Today, I work one of my project's functionality which requires me to
post xml from a server running IIS 6.0 with asp.net to another server
that only runs PHP. Not very familiar on how to implement webservice
with PHP for the .NET counterpart to consume, I do a work around with a
simple Http Post operation from .NET to PHP, modify the source code I
got from
aspalliance
#ASPX
using System.IO;
using System.Net;
public string SaveXML(XmlDocument toSave)
{
return SendAndLoad("http://somedomain/doSave.php", toSave.innerXML)
}
public string SendAndLoad(string url, string data)
{
string result = "";
string strPost = "DATA=" + data + "&";
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally
{
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
StreamReader sr = new StreamReader(objResponse.GetResponseStream());
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
return result;
}
#PHP
$data = $_POST['DATA'];
$data = stripslashes($data) #remove escape code
$dest='file.xml'; #define final destination target name
$fp = fopen($dest, "w", 0); #open for writing
fputs($fp, $data); #write all of $data to our opened file
fclose($fp); #close the file
?>
The codes runs great. A lot of source code available online now only
allowed a one-way trip. That is , once we post out data to a new page,
we simply lost track of it. This piece of code allow us to load back
some result, so I can check if any error occurs in the PHP counter
part. One significant problem now is security. This piece of code only
works in terms of coding, deployment wise very insecurity, so that will
be something I need to worry tomoro. =X
-Edited on 26th Apr. We need to use stripslashes to remove the additional escape code '\' append to the XML string. Thanks to Poh Leng for helping
Article on how to implement a
MVC architecture with actionscript.
Nice to see how actionscript is moving towards a more OO environment
(as compared to the time when scripts are placed directly on
movieclips! yucks!).
Recently reading more and more articles on AJAX on several blogs I subscribe to, like this
one
Hope can read more and experiment with
AJAX Wrapper on .NET it in the weeks to come =)
One interesting topic discussed about during Macromedia Max conference
2005 last month was the comparison between Macromedia 's Rich Internet
Application and normal HTML forms (aspx, php, jsp, etc). One argument
James Talbot pointed out on why
Rich Internet Applications
(built with Flash/Flex) is better is because with RIA, we can
significantly cut down on the post back time and thus
removing/minimizing the post back lag presented to the users. With AJAX
however, this problem can be solved as we could now asyncronously do
the postback. I will try to research more into both form of
presentation (Flash/Flex vs Forms with AJAX) and compare them and see
what is the advantages and disadvantages in time to come.
After my morning run today, I decide to watch Infection and eat some
Ajisen ramen at Junction 8 for the morning part. The suggestion for the
movie on golden village website is "contain disturbing scenes". Indeed,
I was quite 'disturbed' after watching it. There is no explicit scenes
of gore, but its the idea and the plot that is greatly disturbing. This
does not mean the movie is 'yet another imported ghost movie'. It
explores a lot of issues and also features great sound track n plots.
The only pitfall is the ending tries to reveal a bigger "truth" (it
seems that a lot of movies are attempting to do this after 'the others'
and 'six sense'), which is..in my view..a bit lame.
Watching the movie kills my appetite. Went home to prepare teaching material for my night class straight after watching.. =X
Today, after reading the lastest issue of Chip magazine, I was
introduced to a desktop search software named lookout. Lookout
integrates with Outlook and index your Emails and documents and MSN
chat history for quick search of data. Since I save all my SMS in
my Outlook, and also redirect all my RSS feeds to it using You Subscribe, that means I could search most of my messages and
stuff, and newsfeed with a click.
After installing it, the result was quite amazing, about to find all my
sms/msn chat history with a particular person with just 1 click. Type .NET and all the newsfeed on .NET appears.
However, the real problem is the indexing process. Maybe its my
laptop's power (tablet running at 512ddrram), indexing always gives me
problem. Lookout will check if the processor is busy and will index
only if the processor is idle. However, when it is indexing halfway and
I try to stop it, half of the time it will crash. Then again, I must
emphasize that it might be due to me running several application at one
time. Also, once it has start indexing, my outlook will crash often or
so. I will need to restart outlook to check my email again. This
provide me with a contradiction. With Lookout running, I can search for
mail fast but cannot check my mail.
Lookout website :
http://www.lookoutsoft.com/Lookout/
Lookout has been acquired by MSN if I am not wrong
I tried another desktop search software enfish 6.1 professional. It
works similar to lookout. The only problem is that it provides me with
the 'cockpit' type of user interface which I don't really like. Other
than that, its still worth a try (its not free though)
Will experiment with them more when the May holiday comes, now, its time 'lookout' for exam notes en 'fish' for tips.
When I develop web application, I want to keep postback as minimum as
possible, so I always use htmlinputhidden to store values from the
server onto the Html page itself so my javascript can get it later and
thus cutting back on the postback. The data stored in this way must be
of cost something that is not of security concern. Today, I was doing a
functionality where by we have a drop down list on the right, and a
list of labels on the right, so whenever the user select an option in
the drop down list, the right side will populate automatically. I could
have conveniently put the bulk data as part of the Dropdownlist's Value
field, but using htmlinputhidden allow me to have several controls
refering to the same set of data. Thus, to cut down the postback on
each selection change, I do something like this, using HtmlInputHidden.
C#
private void BuildTree(XmlNode element , string Parent)
{
int Index = 1;
foreach(XmlNode e in element.ChildNodes)
{
string NodeName = e.Attributes["Label"].Value;
string name = e.Name.Trim().ToUpper();
HtmlInputHidden Hidden = new HtmlInputHidden();
//Hidden.EnableViewState = false; //Optional,
depends on the developer
string ID = "O" + Parent+ "_" + Index;
Hidden.ID = ID;
string Type =
e.Name;
string Label =
e.Attributes["Label"] != null ?
e.Attributes["Label"].Value: "-1";
string Link =
e.Attributes["Link"] != null ?
e.Attributes["Link"].Value : "-1";
string ImageSet =
e.Attributes["ImageSet"] !=
null ? e.Attributes["ImageSet"].Value : "-1";
Hidden.Value = string.Format("{0}|{1}|{2}|{3}",
Type, Label, Link, ImageSet);
this.Hidden.Controls.Add(Hidden); //Hidden Control
is a Panel on the page
this.Drop_SelectPage.items.add(new ListItem(name, ID));
if(e.HasChildNodes)
{ //Build more control recursively
BuildTree(e, Parent + "_" +
Index);
}
Index++;
}
}
Javascript
//script to get the values
function Img_Change()
{
var drop = event.srcElement;
var hiddenID = drop.options[drop.selectedIndex].value;
var hiddenControl = document.getElementById(hiddenID).value.split('|');
//Get the Type
//hiddenControl[0]
//Get the Label
//hiddenControl[1]
//Get the Link
//hiddenControl[2]
//Get the ImageSet
//hiddenControl[3]
}
After the preceding code, I can have more html controls refering to the
same set of the HtmlInputHidden. If there is only 1 dropdownlist
however,
the fastest way is just doing this
this.Drop_SelectPage.items.add(new ListItem(name, string.Format("{0}|{1}|{2}|{3}",
Type, Label, Link, ImageSet)));
I always love code snippets and always complain why Flash Mx 2004 do not have a panel which we can do so. Thus, my VS's toolbox is filled with a lot of snippets and I will take the effort to organise them into categories for easy retreival in times of needs.
2 weeks ago my laptop crash.
I managed to saved it and get it back, however..to my horror, all my code snippets are gone. Very discouraging, but then I guess I am fortunate enuff to be able to save from laptop 'back from hell'
Today was reading off some old entries of GotDotNet RSS when I come across this VS plug it 'CodeXchange'. It was actually posted on early April but I had not been reading the news feed =X.
With this plug-in, developers can share snippets from a single common database. Very useful indeed!
More details @ http://www.codexchange.net/
Another useful stuff I used when developing 3dsense Admin site is this Tree view downloadable @ http://www.obout.com/t2/download.aspx
Very easy to use Treeview for asp.net. With it, I was able to represent the entire structure of the admin site with a tree structure (much like mapping the sitemap onto the tree), and allow the admin to view the property of each page and then updating it just by interact with the tree. Was actually having a headache on how am I going to provide an easy to use UI for the admin. With the Treeview, this problem is solved. =)