Pages

Thursday, July 2, 2009

Making sense of ASP.Net Paths

ASP.Net includes quite a plethora of properties to retrieve path information about the current request, control and application. There's a ton of information available about paths on the Request object, some of it appearing to overlap and some of it buried several levels down, and it can be confusing to find just the right path that you are looking for.

To keep things straight I thought it'd be a good idea to summarize those options briefly along with describing some common scenarios of how they might be used.


Click here for details .......

Saturday, June 27, 2009

Future of Searching and RSS

I'll admit I was excited when the Google API was made available for public use. Nice idea and opens up some cool new ways to integrate searching into your applications or websites. That is, as long as you don't exceed the allowable 1000 queries per day as per the developer license. It was easy enough to use but it was still not enough to get me that fired up about using it. I have that same excitement now about the MSN Search (beta) site. But this time things are different. There is no daily query limitation, there is not even an API. MSN Search allows you to take any query/search and get the results back as RSS/XML. Now we're talking!

Append the QueryString “format” parameter to specify that you want the results back in the form of RSS. For example, if I do an MSN search for “Ryan Farley”, I'll end up with the following:

Now, if I want that same search back as RSS/XML I simply add the format parameter to the query string as follows:

Not too shabby. But, where this starts to get really cool is how easy it is to seamlessly integrate searching into your own websites, and your users won't even know that MSN is being used for the searches. No redirects to some MSN Search page or anything. You just take the value that they are searching for, append your site URL to the search and then display the resulting RSS from the MSN Search however you want, on your own page, with your sites style. For example, if I wanted to search my blog for something like IDisposable - and get back the results as RSS/XML I would use the following:

If you wanted to make things really easy on yourself, you could use something like Scott Mitchell's RssFeed ASP.NET server control to easily display the returned RSS with no coding on your part. All you have to do is form the search query string and set it as the DataSource to the control and you've got instant searching for your site, all courtesy of the MSN Search.

Setting the Value of a TextBox with TextMode=Password

When the TextMode property of an ASP.NET TextBox is set to Password the value set in the Text property will not display at runtime. This can be a pain, however it is actually by design to prevent the unmasked password from being displayed in the HTML source of the page.

While the security reasons are good to not display the masked password value, leaving it unmasked in the source, it is also necessary at times to display the masked value in the TextBox. For example, a user profile page where the user has the ability to change their password. It makes sense to display it there. After all, the user has already authenticated to get to the page (although the value is sent with the data to the browser and could easily be sniffed).

Security reasons aside, you can work around this by adding the password value to the control as as Attribute. Since the TextBox renders as an HTML input control, you can set the value attribute easily, just as you would set the Text property.

PasswordText.Attributes.Add("value", "ThePassword");

Use this to set the value, instead of setting the Text property. You can still read the value from the control via the Text property.

Thursday, June 25, 2009

A Simple Image Slide Show

This is a simple C# application that can open and view images, and show the images one by one in a slide show. The purpose of this article is for a beginner to know how to create an image slide show using timers, in C#.

Click here for details .......

Tuesday, June 23, 2009

A Complete URL Rewriting Solution for ASP.NET 2.0

This article describes a complete solution for URL rewriting in ASP.NET 2.0. The solution uses regular expressions to specify rewriting rules and resolves possible difficulties with postback from pages accessed via virtual URLs.

Why use URL rewriting?

The two main reasons to incorporate URL rewriting capabilities into your ASP.NET applications are usability and maintainability.

Click here for more details ......

Monday, June 22, 2009

Howto: Create a Custom Control in ASP.NET (C#)

Creating custom controls can save you a lot of time and effort when building an application. The built-in sever controls provided can do just about anything you need them to, but sometimes it takes a great deal of coding (hacking) to make it do exactly what you want it to do. Consider the possibility that you need a textbox control that you would like to be able to assign a readony property to it so it either renders as a regular textbox if false or plain text if true.

You may also want a textbox that will cause it's on "OnTextChanged" to bubble up in the "GridViewCommandEvent" of a Gridview control. By default the textbox does not support that.

Click here for details .....

Saturday, June 20, 2009

Accessing the Html Header in ASP.NET 2.0

Taking a look at the Page class there is a Header property that looks tempting to be able to do something like dynamically add a stylesheet. The problem is that when you type in Page.Header it doesn't appear that you have full control over the header, even though there is the ever so tempting System.Web.UI.HtmlControls.HtmlHead class. What I had been doing is throwing an id and a runat="server" onto the head tag in my HTML, which I really didn't like because an id tag on the head tag isn't valid XHTML 1.1.

Today, a break through. This has always bothered me, so I took a deeper look and it turns out that Page.Header is defined as IPageHeader. Perhaps, just maybe I could cast Page.Header into System.Web.UI.HtmlControls.HtmlHead. And sure enough, it worked great. Anyways, I feel a little silly about not figuring that out sooner but now that I've gotten this working I feel much better. Anyways, here's some example code to add a stylesheet to a page:

Dim header As Web.UI.HtmlControls.HtmlHead
header = TryCast(Me.Page.Header, Web.UI.HtmlControls.HtmlHead)
If header IsNot Nothing Then
Dim link As New HtmlLink
link.Attributes.Add("href", "~/whatever.css")
link.Attributes.Add("media", "screen")
link.Attributes.Add("rel", "stylesheet")
link.Attributes.Add("type", "text/css")
header.Controls.Add(link)
End If

Tuesday, June 16, 2009

Make your web application run faster

It is easy to develop your own ASP.NET web application. But making it do some useful things for your users while keeping the design simple and elegant is not so easy. If you are lucky, your web application will be used by more than a handful of users, in that case, performance can become important. For some of the web applications I worked on, performance is vital: the company will lose money if users get frustrated with the slow response.

There are many factors that can result in bad performance, the number of users is just one of them. As a developer in a big corporation, you usually don't have a chance to mess with real production servers. However, I think it is very helpful for developers to take a look at the servers that are hosting their applications.

For more details, Click here ......

Programmatically Manage IIS

This article is about managing IIS programmatically. It provides a class library that represents the tree hierarchy used by IIS for its every aspect. The project is accompanied by a Windows Forms applications that is used to pinpoint and extract any data required.

Click here for details .......

Sunday, June 14, 2009

Dynamically Adding Meta Tags in ASP.NET 2.0

The HtmlMeta class is provided to created meta tags dynamically in your page header.

You can easily create a HtmlMeta object and add it to the Controls collection in the HtmlHead class exposed via Page.Header.

Here is the sample:

Custom Adding Title Tag :

Me.Header.Title = "Title Of Page Here"

Custom Adding Meta Tag :
Dim metaDescription As New HtmlMeta()
metaDescription.Name = "description"
metaDescription.Content = "A description of page here."
Me.Header.Controls.Add(metaDescription)