mercredi 26 septembre 2012

ASP: how to get a file extension

While we have already seen how to upload files and how to work with the Scripting.FileSystemObject, today we are going to see how to get a file extension, for example before authorising a user to upload a file to our server. We all know very well how important is security when working with the file system objects: for example, we don't want the user to upload executable, or other potentially malicious files on our server.
Said that, we can create a short ASP function to check the file extension, and grant or deny the upload.
Let's see how...

The code
With the FileSystemObject, we need to use the GetExtensionName() method. We can, for example, use something like:
<%
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")

With Response
.Write "The file extension is: "
.Write fso.GetExtensionName("test.txt")
End With
Set fso = Nothing
%>
The above code will output  the following:
The file extension is: txt
If we pass the file name to a function which will grant the upload or display a warning and stop the upload, everything will be under control.

I hope you find the above information of some use.
If so, just drop a line...

mercredi 26 septembre 2012 by Berland · 0

lundi 24 septembre 2012

ASP: how to keep track of downloaded files

Today we are going to see how we can keep track of downloaded files in a web site.
We normally link files with an hyperlink. The trick in this case is to pass the file information to another ASP page and then - after "taking note" of the relevant information - initiate the download.
Ready to see the code? Follow me...
The code
Ok folks, this time things are very easy.
We need to create hyperlinks to files like:

<a href="dwnchk.asp?filename=test.zip">Download test.zip</a>
The above code will simply redirect the user to another page (dwnchk.asp). At the same time we are passing the information needed to complete our "evil" plan: keep track of what is downloaded!

When the dwnchk.asp page is loaded we just need to get the filename, pass it to a DB or whatever we prefer. For example we can increase a counter on a db: if the file name is already there, increase a counter by one, if not create a new record and set the counter to one.
All the above is easily done... if you read The web thought you can find all you need in order to create suitable queries.
When the db update is done, we can initiate the download with something like:
Response.ContentType = "application/x-zip-compressed"
Response.Redirect request("filename")
Easy, isn't it?

This is really a simple solution as you can see... Just one more thing! Remember: don't write any HTML code in dwnchk.asp.

lundi 24 septembre 2012 by Berland · 0

mercredi 19 septembre 2012

SQL Server: SQL Server maintenance solution

Today we are going to see a wonderful set of utility, we might need to manage our SQL Server.
We are talking about SQL Server maintenance Solution.

"The SQL Server Maintenance Solution comprises scripts for running backups, integrity checks, and index and statistics maintenance on all editions of Microsoft SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, and SQL Server 2012. The solution is based on stored procedures, functions, the sqlcmd utility, and SQL Server Agent jobs. I designed the solution for the most mission-critical enterprise environments, and it is used in many organizations around the world. Numerous SQL Server community experts recommend the SQL Server Maintenance Solution, which has been a Gold and Silver winner in the 2011 and 2010 SQL Server Magazine Awards. The SQL Server Maintenance Solution is free."

As you can see, it is a bunch of scripts. Basically we are able to perform:
  • SQL Server Backup
  • SQL Server Integrity Check
  • SQL Server Index and Statistics Maintenance
Each section of the web site describes what the related utility is doing.

"DatabaseBackup is the SQL Server Maintenance Solution’s stored procedure for backing up databases."
"DatabaseIntegrityCheck is the SQL Server Maintenance Solution’s stored procedure for checking the integrity of databases."
"IndexOptimize is the SQL Server Maintenance Solution’s stored procedure for rebuilding and reorganizing indexes and updating statistics."

All the above are supported on SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, and SQL Server 2012.

Every utility is fully described and usage examples are given. Said that I don't think I should spend more words: go to the above web site and have a look for yourself!

mercredi 19 septembre 2012 by Berland · 0

lundi 17 septembre 2012

jQuery: dNotify - A simple user notification plugin for jQuery

Today we are going to talk about dNotify, a simple user notification plugin for jQuery.
The way this simple plugin works is very interesting. Because I usually hate when popup message start to - well - pop up all over the web site, I've found dNotify quite unobtrusive. Moreover, we should consider the use of dNotify in web applications, where we do need to interact with the user more than in other situations.
What makes the plugin almost unique is the fact we can control everything about the notification.
Let's see how we can use it.

Download and include
Well... as usual, we need to dowload the .js and css files from the github repository (follow the link above). After that we need to include jQuery and the plugin, together with the stylesheet:

<link rel="stylesheet" type="text/css" href="/css/dNotify.css" media="screen" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.dNotify.min.js"></script>
Check the path for your files and change them according to your site structure.

Usage
The basic usage is quite simple:
$(document).ready(function() {
    $.dNotify('good', "Welcome to The Web Thought test page! :)", {duration: 3000});
});
however, we should use a different way of showing the notification message. I know it looks more complicated, but if we need to benefit from the plugin parameters, the following code should be used:
 $.dNotify("show", {
    message: "Test",
    sticky: false,
    duration: 2000,
    type: "good"
});
Now, what's all that? Let's move on and see the available parameters.

The parameters
The list of the possible parameters is:
stickyboolean - if false the message will be shown just for a specified period of time, if true the message is permanent, and the user needs to click on the message to close it
durationmilliseconds - for non sticky message, it sets the message duration
slideTimemilliseconds - it sets the animation duration (show/hide of message)
message"text" - the message to be shown
type"good", "bad" or "warn" - type of message
showIconboolean - if true, the message has an icon
iconPosition"left" or "right" - it sets the icon position
iconFilethe file to be used as icon

The CSS and other methods
As we have seen above, we have to include a .css file together with the plugin file.
The css file can obviously be manipulated to change, for example the type of message (good, bad or warn).
At the same time dNotify has some other interesting methods like:
$.dNotify(“close”, "type”);
that closes all message of the specified type. While
$.dNotify(“closeAll”);
closes all messages.


Conclusion
There's not much more to say about dNotify. I've found it quite useful and highly flexible, as I said, specifically in web applications.
See for yourself and let me know what you think - as usual.

lundi 17 septembre 2012 by Berland · 0

mercredi 12 septembre 2012

IIS: customised error messages

Hey everybody! Today we are going to work on IIS, and give those boring error messages a new look.
Customising error pages is an underestimated thing by most web developer. However, as you may understand, it can really make our web site different, and - for example - prevent visitors from going away.
In order to customise the error pages we need to use IIS Manager on the web server. If you're not the server administrator, you can always ask for help. If your web site is hosted somewhere by some web hosting company, well... check if you've access to such configuration from your web site control panel (if you've such a tool) or ask the company directly.
Now... let's see how to customise error messages.

IIS
We need to consider two possible situations: IIS 6 and IIS 7.
Depending from what we are using, this is where to go:

IIS 6

  • Start IIS Manager
  • Right click the website, and click Properties
  • Click on the "Custom Errors" tab
  • Select 404 and click Edit
  • Set "Message type" to URL and set the "URL" to "/404/404.aspx"
  • Click Ok
  • Click Ok
IIS 6


IIS 7
  • Start IIS Manager
  • Click on the website
  • Go down to "Error pages" (in the IIS group) and double click it
  • Select 404 from the list and click Edit
  • Change to "Execute a URL on this site", and specify "/404/404.aspx"
  • Click Ok
IIS 7

If you want to try the custom 404 error locally, you also need to do the following for IIS 7:
  • Click "Edit Feature Settings..."
  • Select "Custom error pages" and click Ok
As you can see, it's not that difficult!

Why do it
In my opinion there are different reasons why we should customise error messages. As long as we have access to IIS console on the server, we should change those awful error messages with something more user friendly.
The first effect is that with a 404 error, the visitor is immediately aware of the fact that the web site is not down, it is not vanished from the web.
Secondly, we could redirect the visitor after a while. That way we can inform the visitor of the error, and subsequently redirect him/her to an appropriate page.

Have you ever used such customisation? Were you aware of it?
Share your experience using the comments section below...

mercredi 12 septembre 2012 by Berland · 0

lundi 10 septembre 2012

CSS: a shadow on just one side of a box

The following trick is quite interesting: we are going to create a box shadow only on one side of a box with CSS.
Just to be clear, something like:


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

I just added a white background to make it more clear...
Do you like it? Let's see how to do it.

The code
The above box is a div. The actual CSS code behind it is quite simple:
<style>
.box {
-webkit-box-shadow: 0 18px 14px -14px rgba(0,0,0,0.6);
-moz-box-shadow: 0 18px 14px -14px rgba(0,0,0,0.6);
box-shadow: 0 18px 14px -14px rgba(0,0,0,0.6);
border: 1px solid #333;
width: 40%;
color: #000000;
padding: 15px;
}
</style>
As you can see we used the box-shadow property.
Box-shadow has 6 possible values:
1) h-shadow (position of horizontal shadow)
2) v-shadow (position of vertical shadow)
3) blur (blur distance - optional)
4) spread (shadow size - optional)
5) color (shadow color - optional)
6) inset (type of shadow - optional)

In our code we played with the vertical and horizontal position of the shadow.
The horizontal position is set to 0 so the shadow is not present on the left side and right side of the box.
We set to 18 the vertical position. because it's a positive number the shadow will appear on the bottom border of the box.
We set to 14 the blur, to -14 the spread and we used rgba for the shadow colour.
Easy isn't it?

Following the above idea, it's easy to move the shadow on the left, the right or the top border of our box.
Top:
box-shadow: 0 -18px 14px -14px rgba(0,0,0,0.6);
Right:
box-shadow: 18px 0 14px -14px rgba(0,0,0,0.6);
Left:
box-shadow: -18px 0 14px -14px rgba(0,0,0,0.6);
And that's all. I hope you enjoyed the post and keep on following The web thought.

lundi 10 septembre 2012 by Berland · 0

mercredi 5 septembre 2012

CSS: Firefox 16 and prefixes

I don't know if you are using Firefox or not, but the following information are quite important to any web developer.
We are talking about some CSS3 properties which are now supported by Firefox with prefixes.

I've already showed a way of removing those annoying prefixes from our code in a specific article, however it seems that the new version of Firefox (the 16th) will get rid of some of them.

According to Paul Rouget (who work at Mozilla) there's an unprefixing work in progress for Firefox 16. Specifically they are going to remove prefixes for:
- CSS3 Animations
- CSS3 Transitions
- CSS3 Transforms
- CSS3 Gradients
- IndexedDB
and probably for calc() as well.

What's in for us, web developer? A possible nightmare if we have been not very careful.
In fact in the near future, the unprefixed properties will be the only one supported by the browser. It means that we are facing a potential complete review of our CSS code. If we forgot to use unprefixed properties, the prefixed ones will not work. And the nightmare is not finished: what about users who don't update their browsers?
We need to consider all possible situation. If in the past we had to use prefixes for Mozilla and for Webkit, now we have to be sure the unprefixed property is there as well.

I'm sure that if you're reading The web thought, you already know how important is to plan your code. And if so, you have already taken into account the possibility of unprefixed properties.
If not, well it's better to start worrying and to start planning a review of your CSS code.

mercredi 5 septembre 2012 by Berland · 0

All Rights Reserved Blogging Tips | Blogger Template by Bloggermint