Posts

Showing posts from 2009

Creating a Secure Base Page class for ASP.NET Pages

Every web application developed using .NET as application framework needs authentication as well as authorization. ASP.NET provides 2 types of authentication providers for the web applications, namely Windows Authentication Provider and Forms Authentication Provider . Am not going to discuss these types and various modes of authentication. But am going to write about how one can implement a code to secure their web pages. And specially if these pages require some kind of user login is a mandatory. First, you create any page that is supposed to be secured, say for instance AccountDetails.aspx. This page by default takes the inheritance from System.Web.UI. Page class. Now that you have created the page, it is the time for you to induce the security for this page. So add a new class to your application and name that as SecureBasePage .CS. This class is now inherited from System.Web.UI. Page class. The code would look like below public class SecureBasePage : System.Web.UI. Page { pub

Tools I’ve installed

  Today, I'd to format my system. After successful installation, the following are the tools that are of my choice to install. WinMail from Live.com Windows LiveWriter from Live.com msdnReader from this link The Architecture Journal from this link . This link is not working, but if you go to the archives, you might find. If you fail to download there, then drop me a mail. I’ll try to upload that to some free upload source. Xobni for Outlook I started using Pidgin for multi chat client, but now moved to Digsby . An RSS tool, FeedDemon from Newsgator Baraha for local language typing. Twhirl for following my tweets from Twitter as well as కువకువలు , a telugu twitter Seven types of browsers. IE, FF, Opera, Flock, Apple Safari, Chrome and Wyzo ( liked it just because of pictures search tool) Am a .NET Developer, so Visual Studio 2008 along with SQL Server 2005 Am also a community person, so to support or reach directly onto the systems away from me and the folks

FireFox file full path – Security Issue

when you use the file upload using either ASP:FileUpload or html input control which is a type of file, FireFox doesn’t give you the full path of the selected file. For this purpose i have used both the controls as mentioned below < asp : FileUpload ID ="fleUpLd" runat ="server" /> < input type ="button" id ="btnDD" value ="File - Upload " /> Now that I’ve used both, i tried to get the full path of the selected file. Well, you’ll get the full path of the selected file, when this page is viewed in IE, but not in FireFox. I did a full search on net for getting the full path of the file, but my search went in vain. There are many snippets that did some attempt to show case the full file path. some thing like, using the onchange event with the help of this.value , but that would also show  you only the file name when fired in FF. The code is some thing like the below < input type ="file" name =&quo

What this could be?

Image
Is this not a bug in windows XP? ----------------------- Desclimer: What ever you read here is out of my own experience. No one shall be made responsible for the contents and issues that are mentioned here.

What happen when we add runat=“server”

We all know that there are 2 types of controls that are available while developing web applications. They are HTML Controls as well as Server Controls. The main difference between these two controls is just the runat attribute. For any normal HTML Control like input, it becomes server control when you add the runat=“server” attribute. By adding this attribute, we can work with the control at code behind directly with out having any difficulties. But did you ever thought what happens when you add this attribute? The secret is that, the visual studio IDE creates a .designer.cs file as a code base for our .aspx page. This code base file is automatically generated, and we have nothing to do there. The purpose of this code base is to construct the controls that have the runat attribute. What do you say?

Enabling / Disabling Required Field Validator using JavaScript

Image
In our current application there is a requirement in one of the pages that when the an user is requesting for a some information, there are some options like Passport Number, Social Security Number are optional values to be submitted. And the client wanted them to be check boxes, because, the end user may submit more than one values. Here comes the actual trick, when the end user selected any one option, the text box next to that should be required. The UI would be some thing like the below   And the code for that is as mentioned below < asp : CheckBox ID ="cbPassport" runat ="server" Text ="Passport Number" onclick ="disableRFV(1)" /> < asp : TextBox ID ="txtPassportNumber" runat ="server"></ asp : TextBox > &nbsp; < asp : RequiredFieldValidator ID ="rfvPassport" Enabled ="false" Display ="Dynamic" EnableClientScript ="true" ControlToValidate ="txtPasspo

GridView with Hyperlink

Recently we have encountered a requirement where there is a page with simple details and a link for each record in that page take you to another page. This another page would have all the details of the selected record of the previous page. Let me rename these as ClassRoomPage containing the names of the students and their respective roll numbers and the second page is StudentDetailsPage where we pass a parameter as Student ID. So what we did is, we had the first page as ClassRoomPage with GridView and binded that with the respective columns. The trick is that we need a hyperlink to navigate to the next page along with the query parameter. So we added a template column with the hyperlink as mentioned below < asp : TemplateField HeaderText ="Comment"> < ItemTemplate > < asp : HyperLink id ="hlview" runat ="server" NavigateUrl =' <% #"~/StudentDetails.aspx?RollNumber="+ Eval("RollNum") %>

Month Name from Month number

Today, there was a requirement to show the month name in a text box. There are two forms that we have to show, depending on the user choice. The choices being the full name of the month as well as short name. Something similar to that of “October” for full name and “Oct” for short name. We know that we get the month number from DateTime object. This DateTime object has many properties that are directly associated to show the different parameters of Date and Time of the day. But now, for our requirement, you can get the full name of the month with the help of the Globalization object. That is too complicated. The simple method is to use the ToString() with the format that is required. DateTime .Now.ToString( "MMMM" ) Give you full name DateTime .Now.ToString( "MMM" ) returns you short name as required How is this?

Schedule a Task on an Hourly Intervals

Image
We know that we can schedule any task for specific intervals as defined in the basic configuration. Before we talk about any thing, let me write about how to schedule windows scheduler.   Start => Control Panel => Scheduled Tasks   For more details, you can read the instructions as explained at by Microsoft at the knowledge base . But the missing part is that the KB article doesn’t help you to schedule on a reduced intervals or specific intervals. Just before you click the Finish button, make sure that you check the Advanced Properties button. Once you select this option, you would be taken to the next screen. At times you would not be able to see that due to not providing the Account Information to access the local system If that is not your case, you are lucky to proceed next step. Other wise, you would see the below window. The only difference is that the below window doesn’t contain the Security tab. Now, if you forget to check above “Advanced Properties” checkbox, yo

Coding Guidelines

We are lucky to have a client that is tech savvy. And most of the times our code is being reviewed by their tech architects.  Most of the times we get reviewed our code on a frequent time intervals. On one side it is good, on the other side it leaves our developers with some morel loss. Adding to the fuel, is me. I insist my developers to follow certain standards within their code. It is time to post the general points that I emphasize. 1)    Use long names for variables 2)    Initialize variables at the time of declaration 3)    Use .Equals instead of == 4)    Use territory operator ?: 5)    Use ?? when expecting the null reference 6)    Use .Length() comparison  to validate string with values 7)    Use StringBulder instead of strings concatenation 8)    Use StringBuilder replace instead of string (Ref : http://dotnetperls.com/replace-string-use) 9)    Use single line assignments for common values 10)    Avoid try catch as much possible 11)    Organize Usings and remove & sort th

Copy binary table data from diff servers

Today, before we start an internal demo of our project, we realized that, on a particular table there is no data in the QA server. We have every thing ready, but no the sample data. We just can’t create an insert script from the table and execute the script there, because, there is a column which is binary type. When we generate the script, the binary data type is not able to populate. Then we are struck with a big question of how to transfer the data between servers. Let me explain you much in detail about our infra structure. We have a dev DB server for our internal development hosted on 192.168.2.10 <<local ip address; for our convenience >> We have a test bed for our application and IIS installed on it, let’s say this is 192.168.3.10 , which is altogether a different network. And this IIS is connecting to a TestDB Server (let’s say it is hosted on 192.168.3.20 ), where we migrate our DB scripts to create the database / tables / stored procedure / user defined functio

Multiple Validation Groups limitation

Image
Within the single form it is evident that you can have multiple validation groups. To explain more, it is good to throw some light on such requirement. In our current project we have the following requirement. If you observe this screenshot, the “Request a Quote” box is repeated. And on click of “Add More” button, one more “Request a Quote” would be added to the screen. Every time such a box is added, they are generated along with RequiredFieldValidator and adding the ValidationGroup property with the respective item index. In the above case, we have 2 validation groups. Now the problem is about validating the required fields on “Submit” button. If there is only one validation group, you can directly associate the validation group to button with the “ValidationGroup” property. But in this case, we don’t a direct association of single validation group with single button. Hence we need to associate the multiple groups with the submit button, as mentioned below < asp : Button ID =&q

4 Checkboxes – Some tricky issue

Image
Today, almost more than 4 hrs I'd spent on this issue. Do you want to know what is that? Here is that. I have 4 checkbox elements and I have to do the following conditions Condition 1) Any one check box has to selected Condition 2) If any of the first 2 check boxes are selected, my code should throw an exception when the 3rd check box is selected Condition 3) vice versa for Condition 2 A picture is worth of 1000 words. Here is the actual requirement. Hope you got the actual picture. Now here comes the actual twist. You can do that with simple if conditions, but i thought of implementing this using territory operators using a single if condition. And the condition goes like this.. if (((cbRepair1.Checked || cbCalibration1.Checked ) ? (cbBoth1.Checked) ? false : true : (cbBoth1.Checked || cbOnLine1.Checked) ? true : false )== false ){ throw new Exception ( "Duplicate selection .." ); } It took me almost more than 4 hrs. Isn’t it funny!!

CheckBoxList validation

Within our current project, we faced a requirement such that there are multiple checkboxes and the user is required to select any one of them (at least one of them). So as there are multiple checkboxes, decided to go with CheckBoxList control. Now the problem is that, we need to show a error message if the user is not selected any one of them. The problem also extends not just there, but the display text should be culture specific. So the story started long after I've written this post. But editing this entire post due to a simple non supportive feature by IE. I’ll come to that point little later, let me first detail the requirement and solution. There is one more solution for this unsupported error. Please read thru the post. For all the client side validations, it is widely known that validation controls supported by ASP.NET framework are popularly used. But these controls can’t handle the CheckBoxList. Hence the following solution. Step 1: Place your CheckBoxList control in a

Common Myths by Developers

1) Which programming language is faster ? VB or C# ? This is regular and majorly mistaken by the VB developers and mistakenly highlighted by C# developers. According to the .NET architecture every language code is converted into MSIL, hence every language code is common on the first compilation. Then this MSIL is converted onto the native code. The entire purpose of converting the ELL into MSIL is to obtain the Interoperability between Commonly used languages. Hence this is absolutely false, and all we need to remember is that better code generates better performance results and vice versa   2) CodeBehind is better than InLine It doesn’t really matter whether you implement the code in a separate file or with in the same, the reason behind this is .. anyhow, the IIS is going to compile for the first time and going to cache the page DLL. And once this is done, it doesn’t really mean any thing for the IIS towards processing and generating the output HTML from our ASPX page. Hence, it

Blogger Connect Brief

On 22nd of this month, i got a mail from Abhisheik about this event. This is the first of it’s kind by Microsoft to connect all bloggers.  Points that rolled during this meeting are 0) Freebees at TechEd towards. MCP Exam tokens to attend any one exam for free 1) Naked Browser Challenge from http://merawindows.com 2) Silverlight 3 features a) Smooth Streaming b) APIs are open to Plugins new features by community to integrate with Silverlight Give a look at SmoothHD.com for some demos on smooth streaming 3) Release of Expression Blend 3 4) Pandu spoke about Sketch Flow in Expression Blend3 5) Nano Car experience and IPLT20 are developed using .NET technology – a feel good factor. Hope Silverlight streaming would be next generation of media transmission 6) IE 8 and WebSlices and Accelerators are going to be the part of IE8 highlights and key elements of success 7) Interoperability Lab from Microsoft is being setup at Bangalore and this is open for all public with out any

Common mistakes by Interviewer

Now-a-days am conducting few interviews for our organization. While sitting in the other side of the table, I've visualized why most of the interviews fail with me. But when conducting these interviews, most of the candidates are attending with self confidence that they are suitable for the mentioned role and attend without preparation. When people do some real preparation, they tend to fail due to lack of awareness at the interviewer towards interviewing techniques. Having failed in many interviews, I've learned that the interviews fail because of the following... Reflection (or) Mirroring: The interviewer tends to see self within the candidate. The interviewer starts to compare self with the candidate and evaluate. This evaluation is totally personal. The yard stick for measuring the candidature is not generalized, but influenced.   Template (or) Checklist: The interviewer has a template of a questionnaire. The interviewer measures the candidate with respect to the list of st

Security & Silverlight

Image
Yes, am mentioning about Security at Silverlight applications. Well, most of the developers think that Security is not the feature of the application. and they claim that it is the responsibility of the framework on which they are developing, be it as .net or java or any other. Thus, they don’t even worry about why security should be the core of any application and it should be given prime attention. Microsoft has an initiative towards security with in any software development life cycle. This initiative is known as SDL, Security Development Lifecycle. Their definition of SDL is neatly designed as displayed. And also they have released a security guidance document for writing and deploying Silverlight Application. The document can be downloaded from this link . The TOC is some thing like this Threat Modeling and the Security Development Lifecycle Background of Web Security Same-Origin Policy Cross-Site Scripting Attacks Cross-Site Request Forgeries (CSRF) A CSRF Mitigation: Nonces

email Regular Expression

From long time, I've been looking out for a better regular expression for my web application. Every time, I adjust with some freely available expressions and complete the work. But this time, I've decided as not to compromise with what I get for free. And started writing my own expression. My email validator should justify all the following conditions.. 1) it should restrict the user name length between 4 to 50 characters length - {3,50} 2) it should allow dots, underscore, hyphen. But not as starting point - [-.\w] 3) it should allow numerical as well as alphabetic characters of both cases - [0-9a-zA-Z] 4) it should contain one dot after one @ 5) all the chars after @ should be at least 2 characters length and may be up to 20 characters consisting of alphanumeric with both cases After doing all kinds of R&D, concluded as below. Correct me if am mistaken. And extend if you have any further to add --------------------------------------------- ^(([0-9a-zA-Z]([-.\w]*[