Tuesday, July 17, 2007

Internship over!

Since our internship is all over (16/20 :-)), it's time to set sail for new things. Please visit my new blog here!

http://www.dominiek.eu/blog

njoy!

Wednesday, May 2, 2007

ASP.Net Membership ReturnUrl Problem

If you click the Login link on the main page, ASP.Net will auto create a ReturnUrl Querystring. After you logged in succesfully you will be redirected to the page you came from. The problem is that the DestinationPageUrl property won't work anymore if you have a ReturnUrl Querystring. This causes a problem for us because the user will be redirected to the login page instead of the DestinationPageUrl.

We've searched for solutions but there isn't a clean solution. Here's a way to solve the problem (redirect to the Default page if a ReturnUrl querystring is present).

protected void Page_Load(object sender, EventArgs e)
{
string strRedirect;
strRedirect = Request["ReturnUrl"];
if (strRedirect != null)
Response.Redirect("~/Default.aspx", true);
}

Thursday, April 19, 2007

Trick for adding a default image to a Windows Media Player video








When you're surfing the net you see a lot of videos with a default image before it's playing. An embedded HTML video that uses Windows Media Player doesn't have that option. We found a little trick to make it look like there is a default image before it's playing and after it's finished. You can easily implement these function in a javascript in the head of your page.

Steps:
1. When loading the video, you hide the video and you show a default image. Hiding the video is possible by setting the default property document.video.uiMode = 'invisible'
2. Set the uiMode property to 'none' when the video starts playing (check on playing with the property: currentPosition (!= 0)).
3. The image will pop up again after playing because the currentPosition will be zero again.

that's it, add a cool background image like ours :p

Monday, April 2, 2007

Sorting once, sorting twice...

We came across a situation in which we had to sort a table (limited by a WHERE clause) and order this again by another column. We thought this was easy to do using a subselect but SQL Server refuses to sort views. After some experimenting we came up with the following query:

SELECT * FROM
(
SELECT TOP 5 topicKnowledgeID, topicID, rating, tblTopicKnowledge.date, username
FROM dbo.tblTopicKnowledge
WHERE (topicID = @topicID AND username = @username)
ORDER BY topicKnowledgeID DESC
) AS sortedTopicKnowledgeTable
ORDER BY topicKnowledgeID ASC


Great succes!!

Sunday, April 1, 2007

Using System.Reflection

Ever since I read a great article about using the builtin reflection API in C#, I wanted to use it in a real life situation. The idea is that at runtime, you can list classes, get info about their methods, attributes, super class, ... and even make instances of them using the Activator class.

For our import application, which will load data from an Excel spreasheet to an SQL Server 2005 database, we wanted to give the user a scala of ways in which the console application could notify the user. We came up with the following diagram...


The Open methods will be fired first, in the console output class they won't do much but they could be responsible for initializing a stream, connecting to the mailserver...
The Format method is passed an OutputItem object, which contains message data and a category (error/success/default)...
The Close method would close streams, send a mail with all the notifications, contact a webservice...

Now at runtime, we will use reflection to detect all classes which implement the IOutputFormatter abstract class and they will be instantiated by our FormatterReflectionManager class. By default this class will enable all formatters and stack them up in a generic list, but the user can choose which Formatters should be used. The idea is similar to the Enterprise Library, we didn't use the EntLib because it's a really big library and we didn't want to bring in extra dependencies. Another reason why we didn't use EntLib is because we already use it in another project and because we wanted to experiment with System.Reflection...

public void ReflectOutputFormatters()
{
foreach (Type type in Assembly.GetCallingAssembly().GetTypes())
{
if (type.IsSubclassOf(typeof(IOutputFormatter)))
_formatters.Add((IOutputFormatter)Activator.CreateInstance(type));
}
}


This chunck of code will look for all classes the extend the superclass and add them to a Generic List.

Thursday, March 29, 2007

ASP.Net Membership: IsLockedOut property

Hello bloggers!

Today we looked up some info about the ' IsLockedOut ' property of the ASP.Net Membership Control. If a user enters a wrong password more than three times in a row, IsLockedOut will be true. The problem is that a user can't login anymore until an administrator unlock his account.

Password crackers can brute force user accounts. So it can happen you can't login because someone else tried to crack your account with several invalid passwords. To solve this problem, we can just raise the number of maximum invalid attempts.


Well, for those who agree with our statement here are 2 ways to disable it.

Simple Way (and still effective):
Just add the maxInvalidPasswordAttempts property to your web.config file:
example:


Remember, the counter resets when a successful attempt is logged.



Advanced Way (it auto-unlocks your account if you reached the maximum invalid attempts):
Click Here to go to the CodeGuru Tutorial


Changing CSS Styles at runtime
Oh yeah, another quick tip, if you change the css style of a webpage in Visual Studio, you need to Clear your cache before reloading the page. You can do this using CTRL-F5 instead of the normal refresh (F5)

Friday, March 23, 2007

MSSQL Handling NULL Values

One of the most horrific problems in database-access are fields which allow Null-values, I remember all the IF statements it took in COBOL to handle this problem (with a CSV file) and I was afraid I had to go through the same hell as back then. By making use of the ISNULL method we were able to remove the evil at it's root, the database...

An example :

SELECT username, ISNULL(email,"") FROM tblUser

This query will set the emailadres to an empty string instead of a null value if no value is entered.
Since the abilities to handle Null values with Typed Datasets are rather limited, this was a fine solution..