URL Routing with ASP.NET 4.0
URL Routing with ASP.NET 4.0
- Introduction
- Prerequisite
- What is URL Routing
- Why URL Routing
- URL Routing Earlier
- URL Routing with ASP.NET 4.0
- Bidirectional Routing
- Components of ASP.NET 4.0 URL Routing
- An Example
- Feedback and Suggestions
- References
- History
Introduction
One thing that has always pinched me is the long URLs that I used to see in several of my projects. Due to better manageability, I used to have several folders, i.e. folder hierarchy for maintainability of my application. But the thing that I didn’t ever like was the full physical path of pages in URLs. There are other ways which allow us to get rid of it like URL rewriting, but I didn’t like that.
We could also have our own custom URL route handler or some third party solution, but they have never been strong enough for an application.
Frankly speaking, one of my clients asked me several times, “Why does this .aspx extension displays in the URL” and also told me that he does not like these long URLs. I used to tell him, this is the normal behavior of ASP.NET application. But we can change it with our own custom solution. However, that will require a little bit of time and also require a lot of testing.
But when Microsoft released ASP.NET MVC 2 with .NET Framework 3.5 SP1, and provided this Routing feature with it, I was very happy and started exploring it. In the meantime, I thought that it should also be provided with ASP.NET, because every time you may not require to follow MVC architecture and also found that MVC has nothing special to do with URL Routing. So I was expecting and waiting for ASP.NET Webform Routing.
Now Microsoft introduced URL Routing with ASP.NET 4.0. URL routing is fully integrated, very powerful andstraightforward.
Prerequisite
- Visual Studio 2010
What is URL Routing
We access our webapplication using some URL that is normally the physical path of the pages. So URL Routing is a way to provide our own URL in lieu of the physical path of the page. One other way, Routing allows us a way to configure our application to accept a requested URL which actually doesn’t map to physical files. From the security perspective of the application, it’s important because one can easily know the solution structure of the application.
Fig 1.0: URL Routing Processing
Why URL Routing
In 1999, on usability Jakob Nielson wrote on his blog “URL as UI” 6 essential points about URL. These are:
- A domain name that is easy to remember and easy to spell
- Short URLs
- Easy to type URLs
- URLs that visualize site structure
- URLs that are “hackable” to allow users to move to higher levels of the information architecture by hacking off the end of the URL
- Persistent URLs that don’t change
As from all these points, we can see the URLs as a part of user interface and it should be simple and easy. URLs should also made us visualize the structure of our application which might be a security concern for us, etc.
ASP.NET 4.0 provides us the features, taking care of all the points mentioned above.
Also, these URLs helps in SEO (Search engine optimization) and improve the page hits but put in the appropriate keywords.
URL Routing Earlier
Earlier, URL routing was not so easy. For that, we require to have our own custom handler in a way that whenever a URL is requested, our custom route handler class should be invoked, and forward the request to the appropriate requested page or we could have some third party solution. So let’s say if we are going to develop our own customhandler, then what do we need to do.
- We define the mapping in Global.asax, which maps a route pattern to route handler class.
- We require to develop a Route handler class which actually receives the URL, parses it, stores any route parameters into some location that should be accessible to the requested page and returns the instance of requested page or forwards the request to the HTTPhandler that handles the requested route.
- Writing code in the target page in the way so that it can fetch the route parameters and renders the page accordingly.
So you can imagine that it was not a straightforward task. It also requires some considerable amount of effort to develop it.
URL Routing with ASP.NET 4.0
As I already discussed in my introduction section, that ASP.NET 4.0 provides us a simplified and robust way to handle the entire URL routing mechanism. To provide URL routing, ASP.NET is now equipped with myriad classes and a number of methods to provide this feature, which allows to easily decouple the URL with physical files. We just need to use them.
Fig 2.0: ASP.NET 4.0 URL Routing Flow
ASP.NET 4.0 router enables to define any kind of custom routes and we can easily map it to our webform page.
ASP.NET 4.0 also made our life simpler by providing us the feature “Bi- Directional routing” with the help of several components like Route Table, Page Routehandler and ExpressionBuilders.
What is Bi-directional Routing
With the help of the Route table, we can not only decode the Routed URL with the Route table and with the help of other methods provided by the ASP.NET 4.0, we also generate the URL with the ASP.NET routing mechanism, which gives us the opportunity, not to hard code the URL at several places, rather it will be dynamically generating the URLs with the help of Routing Definition.
So we just require to change the Route Table on any changes in the URL, and don’t need to change it in several other places throughout the solution.
Fig 3.0: Bi-directional Routing
Components of ASP.NET 4.0 URL Routing
There are two main components of ASP.NET 4.0 URL Routing.
RoutingHandler
This is basically a normal HTTPHandler, which is responsible for looking into all the incoming URL requests, and looking for any Routing definition available for the URL, if yes, then pass the request and data to the corresponding resource.
Expression Builders
Expressions are provided with ASP.NET 4.0 to facilitate Bi-Directional Routing and more. Basically there are two types of ExpressionBuilders.
- RouteURLExpressionBuilder: As the name suggests, it provides the syntax which results in the value, i.e., URL based on RouteName and Parameter according to the Route definitions we have.
- RouteValueExpressionBuilder: As above, it generates the URL, RouteValueExpressionBuilderprovides a syntax which receives the value from the RouteName and Parameter from RoutedURL.
There are also a few new properties HttpRequest.RequestContext and Page.RouteData which facilitate the availability of the parameters to all resources.
An Example
In this example, I will be displaying the image and name of the book on my web page.
Here, I will be going to an ASP.NET application and will take you step by step to create the application.
Note:
- I have used VS2010 Beta 2 version for this sample.
- We have to use the namespace System.Web.Routing in our application to access Routing specific classes and methods.
Step 1
Define the Route in Application_Start of Global.asax. Also include namespace System.Web.Routing.
Collapse | Copy Code
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteTable.Routes.MapPageRoute(“StoreRoute”,
“BookStore/{Name}”,
“~/Webpages/BookStore/ViewBookDemo.aspx”);
}
Step 2
- Now in ViewBookDemo.aspx, I have four links. In the first two, I have hardcoded the URL and in the last, I usedRoutURLExpressionBuilder to generate the URL dynamically. That is known as Bi- Directional routing. This is the one I also liked the most, in several cases, we have had links in our pages that were generally hard coded.
- I also have a Label in the page and I set the Text property dynamically with the help of Routing information as above.
Step 3
Here, I fetch the parameter from the Routing Table and set the Image1 URL dynamically.(Include namespaceSystem.Web.Routing):
Collapse | Copy Code
//fetching the parameter that is Route table
string name = Page.RouteData.Values[“Name”] as string;
if (name != null)
{
if (name == “CSS”)
{
Image1.ImageUrl = “~/images/css.jpg”;
}
else if (name == “Django”)
{
Image1.ImageUrl = “~/images/django.jpg”;
}
else if (name == “IPhone”)
{
Image1.ImageUrl = “~/images/iphone.jpg”;
}
else if (name == “Linq”)
{
Image1.ImageUrl = “~/images/Linq.jpg”;
}
}
}
To view the entire code, please download the attachment.
Now my solution hierarchy in the demo application is:
Fig 4.0: Solution Explorer
And according to it, my URL should be http://localhost:2039/Webpages/BookStore/ViewBome.aspx?Name=CSS as:
Fig 5.0: Demo Application
Now when a user requests this application, the request is processed as:
Fig 6.0: Request Processing
Feedback and Suggestions
Feedback is the key for me. I would request all of you to share your feedback and give me some suggestions, which would encourage and help me in writing more articles.
References
- http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
- http://haacked.com/archive/2006/11/29/
Express_Yourself_With_Custom_Expression_Builders.aspx - http://sankarsan.wordpress.com/2009/08/09/asp-net-4-0-webforms-routing-part-i/
- http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
Bottom of Form
Website Testing Techniques
Introduction
First, let’s have a web testing checklist:
- Functionality Testing
- Usability testing
- Interface testing
- Compatibility testing
- Performance testing
- Security testing
1. Functionality Testing
Test for – all the links in web pages, database connection, forms used in the web pages for submitting or getting information from user, cookie testing.
Check all the Links
- Test the outgoing links from all the pages from specific domain under test
- Test all internal links
- Test links jumping on the same pages
- Test links used to send the email to admin or other users from web pages
- Test to check if there are any orphan pages
- Lastly in link checking, check for broken links in all above-mentioned links
Test Forms in all Pages
Forms are the integral part of any web site. Forms are used to get information from users and to keep interaction with them. So what should be checked on these forms?
- First check all the validations on each field
- Check for the default values of fields
- Wrong inputs to the fields in the forms
- Options to create forms if any, form delete, view or modify the forms
Let’s take an example of the search engine project I am currently working on. In this project, we have advertiser and affiliate signup steps. Each sign up step is different but dependent on other steps. So sign up flow should get executed correctly. There are different field validations like email ids, user financial information validations. All these validations should get checked in manual or automated web testing.
Cookies Testing
Cookies are small files stored on the user machine. These are basically used to maintain the session mainly login sessions. Test the application by enabling or disabling the cookies in your browser options. Test if the cookies are encrypted before writing to user machine. If you are testing the session cookies (i.e., cookies expire after the sessions ends), check for login sessions and user stats after session end. Check effect on application security by deleting the cookies. (I will soon write a separate article on cookie testing.)
Validate Your HTML/CSS
If you are optimizing your site for Search engines, then HTML/CSS validation is very important. Mainly validate the site for HTML syntax errors. Check if site is crawlable to different search engines.
Database Testing
Data consistency is very important in web application. Check for data integrity and errors while you edit, delete, modify the forms or do any DB related functionality.
Check if all the database queries are executing correctly, data is retrieved correctly and also updated correctly. More on database testing could be load on DB, we will address this in web load or performance testing below.
2. Usability Testing
Test for Navigation
Navigation means how the user surfs the web pages, different controls like buttons, boxes or how user uses the links on the pages to surf different pages.
Usability Testing Includes
Web site should be easy to use. Instructions should be provided clearly. Check if the provided instructions are correct meaning whether they satisfy the purpose.
Main menu should be provided on each page. It should be consistent.
Content Checking
Content should be logical and easy to understand. Check for spelling errors. Use of dark colors annoys users and should not be used in site theme. You can follow some standards that are used for web page and content building. These are common accepted standards like I mentioned above about annoying colors, fonts, frames, etc.
Content should be meaningful. All the anchor text links should be working properly. Images should be placed properly with proper sizes.
These are some basic standards that should be followed in web development. Your task is to validate all for UI testing.
Other user information for user help: Like search option, sitemap, help files, etc., sitemap should be present with all the links in web sites with proper tree view of navigation. Check for all links on the sitemap.
“Search in the site” option will help users to find content pages they they are looking for easily and quickly. These are all optional items and if present, should be validated.
3. Interface Testing
The main interfaces are:
- Web server and application server interface
- Application server and database server interface
Check if all the interactions between these servers are executed properly. Errors are handled properly. If database or web server returns any error message for any query by application server, then application server should catch and display these error messages appropriately to users. Check what happens if user interrupts any transaction in-between? Check what happens if connection to web server is reset in between?
4. Compatibility Testing
Compatibility of your web site is very important testing aspect. See which compatibility test is to be executed:
- Browser compatibility
- Operating system compatibility
- Mobile browsing
- Printing options
Browser Compatibility
In my web-testing career, I have experienced this as the most influencing part on web site testing.
Some applications are very dependent on browsers. Different browsers have different configurations and settings that your web page should be compatible with. Your web site coding should be cross browser platform compatible. If you are using JavaScripts or AJAX calls for UI functionality, performing security checks or validations, then give more stress on browser compatibility testing of your web application.
Test web application on different browsers like Internet Explorer, Firefox, Netscape Navigator, AOL, Safari, Opera browsers with different versions.
OS Compatibility
Some functionality in your web application may not be compatible with all operating systems. All new technologies used in web development like graphics designs, interface calls like different APIs may not be available in all Operating Systems.
Test your web application on different operating systems like Windows, Unix, MAC, Linux, Solaris with different OS flavors.
Mobile Browsing
This is the new technology age. So in future, Mobile browsing will rock. Test your web pages on mobile browsers. Compatibility issues may be there on mobile.
Printing Options
If you are giving page-printing options, then make sure fonts, page alignment, page graphics are getting printed properly. Pages should fit to paper size or as per the size mentioned in the printing option.
5. Performance Testing
Web application should sustain to heavy load. Web performance testing should include:
- Web Load Testing
- Web Stress Testing
Test application performance on different internet connection speed.
In web load testing, test if many users are accessing or requesting the same page. Can system sustain in peak load times? Site should handle many simultaneous user requests, large input data from users, simultaneous connection to DB, heavy load on specific pages etc.
Stress testing: Generally stress means stretching the system beyond its specification limits. Web stress testing is performed to break the site by giving stress and checked how system reacts to stress and how system recovers from crashes.
Stress is generally given on input fields, login and sign up areas.
In web performance testing web site functionality on different operating systems, different hardware platforms are checked for software, hardware memory leakage errors,
6. Security Testing
Following are some test cases for web security testing:
- Test by pasting internal URL directly into browser address bar without login. Internal pages should not open.
- If you are logged in using username and password and browsing internal pages, then try changing URL options directly, i.e., If you are checking some publisher site statistics with publisher site ID= 123. Try directly changing the URL site ID parameter to different site ID which is not related to logged in user. Access should be denied for this user to view others stats.
- Try some invalid inputs in input fields like login username, password, input text boxes. Check the system reaction on all invalid inputs.
- Web directories or files should not be accessible directly unless given download option.
- Test the CAPTCHA for automates scripts logins.
- Test if SSL is used for security measures. If used, proper message should get displayed when user switches from non-secure http:// pages to secure https:// pages and vice versa.
- All transactions, error messages, security breach attempts should get logged in log files somewhere on web server.
I think I have addressed all major web testing methods. If I missed out addressing some important web testing aspect, then let me know in the comments below. I will keep on updating the article for latest testing information.
Bottom of Form
Database Coding Standards and Guidelines
Database Coding Standards and Guidelines
1. ANSI SQL 92 standards have to be followed for writing queries.
2. Do not put order by clause in the query unless required.
3. Do not encapsulate readonly database operations in transactions.
4. Use a stored procedure with output parameters instead of single record SELECT statements when retrieving one row of data.
5. Stored procedure execution is fast when we pass parameters by position (the order in which the parameters are declared in the stored procedure) rather then by name.
6. After each data modification statement inside a transaction, check for an error by testing the global variable @@ERROR
7. Verify the row count when performing DELETE operation
8. Use RETURN statement in stored procedures to help the calling program know whether the procedure worked properly.
9. Key words should be capital. For example; SELECT, UPDATE, DELETE, INSERT, FROM, AND WHERE, etc.
10. Do not use “SELECT * FROM” type of query. If all the columns of the table are to be selected, list all columns in the SELECT in same order as they appear in the table definition.
11. While writing a query as a string, do not put any space after single quote (‘). There should be a single space between every two words. There should not be a space between the last word and the concluding single quote (‘).
12. Where multiple columns are selected, there should be a single space after every ‘,’ between two columns.
13. All the major keywords should come on the new lines
14. The number of columns in a SELECT statement should not be more than 6. The line separator should be placed in this case after the (,) of the last column of this line and a single space.
15. For any new line separator, the separator should come after a single space after the last word of the line.
16. Place a tab after each key word on a new line.
17. Use transactions when you are involving with multiple DML statements inside a stored procedure. This ensures all or non principal.
ASP.NET Coding Standards and Guidelines
1. Prefix user control names with “uc”
2. The rest of the user control name should be in Pascal Casing (Ex. ucMyUserControl)
3. Do not use session variables throughout the code. Use session variables only within the classes and expose methods to access the value stored in the session variables.
4. Do not store large objects in session, it may consume lot of server memory depending on the number of users.
5. Always use style sheet to control the look and feel of the pages.
6. Categories data and store it in predefine folder depending on its working.(e.g.- store all images, sound, video files in media or image folder)
Control Name | Abbreviations/ Prefixes | Remarks |
Form | wf,frm | |
Textbox | Txt | |
TextArea | Txa | |
Checkbox | Chk | |
Check Box List | Chklst | chklstCurrency |
Label | Lbl | |
Hidden Elements | Hdn | |
Combo Box / Drop Down | Cbo | |
Button | cmd,btn | |
Submit Button | smt | |
Reset Button | rst | |
Link Button | lbtn | lbtnSave |
Image Button | ibtn | ibtnExit |
Password Field | pwd | |
Radio Button | opt | |
Radio Button List | optlst | optlstSelect |
List Box | lst | |
Frame | fra | |
Image | img | |
Pointer | ptr | |
Panel | pan,pnl | pnlBackground |
Place Holder | plh | |
Calendar | cal | |
Ad Rotator | adr | |
Table | tbl | tblAppointments |
Range Validator | rav,rgv | |
Regular Expression Validator | rev | |
Regular Field Validator | rfv | |
Compare Validator | cmv | |
Custom Validator | cuv,csv | |
Validation Summary | vsm | |
XML | Xml | XmlDataFile |
File Field | Fle | |
Literal | Lit | |
Arraylist | Al | |
Hyperlink | hyp | |
DataGrid | dtg,dgr | |
DataList | dtl | |
Repeater | rpt | rptReport |
Flow Layout Panel | flp | |
Grid Layout Panel | glp | |
Horizontal Rule | hr | |
Crystal Report Viewer | crv,crvr | crvReport |
Visual Studio 2010 & .Net Framework 4.0
I found an Article about Visual Studio Team System (VSTS) 2010. I was amazing to see the Microsoft Announcement. Because till now most of the developers (me also) dint use the Visual Studio 2008. And don’t know much about Framework 3.5. But being a programmer we have to update our knowledge with current technology. So I decided to start VS2008 as soon as possible….!
So..Here I am mentioning some details about VS2010. Microsoft Announce that this Framework as .Net Framework 4.0 and it code name is “Rosario”. The main features are collaborative development, modeling, and debugging.
In This Framework Major pillars are..
- Democratizing Application Lifecycle Management(ALM)
- Enabling emerging trends
- Inspiring developer delight
- Riding the next generation platform wave
- Breakthrough Departmental Applications.
Design Pattern
Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.
The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral. Here you will find information on these important patterns.
To give you a head start, the C# source code is provided in 2 forms: ‘structural’ and ‘real-world’. Structural code uses type names as defined in the pattern definition and UML diagrams. Real-world code provides real-world programming situations where you may use these patterns.
A third form, ‘.NET optimized’ demonstrates design patterns that exploit built-in .NET 2.0, 3.0, and 3.5 features, such as, generics, attributes, delegates, object and collection initializers, automatic properties, and reflection. These and much more are available in our Design Pattern Framework 3.5TM. See our Singleton page for a .NET 3.5 Optimized code sample.
Creational Patterns | |
Abstract Factory | Creates an instance of several families of classes |
Builder | Separates object construction from its representation |
Factory Method | Creates an instance of several derived classes |
Prototype | A fully initialized instance to be copied or cloned |
Singleton | A class of which only a single instance can exist |
Structural Patterns | |
Adapter | Match interfaces of different classes |
Bridge | Separates an object’s interface from its implementation |
Composite | A tree structure of simple and composite objects |
Decorator | Add responsibilities to objects dynamically |
Facade | A single class that represents an entire subsystem |
Flyweight | A fine-grained instance used for efficient sharing |
Proxy | An object representing another object |
Behavioral Patterns | |
Chain of Resp. | A way of passing a request between a chain of objects |
Command | Encapsulate a command request as an object |
Interpreter | A way to include language elements in a program |
Iterator | Sequentially access the elements of a collection |
Mediator | Defines simplified communication between classes |
Memento | Capture and restore an object’s internal state |
Observer | A way of notifying change to a number of classes |
State | Alter an object’s behavior when its state changes |
Strategy | Encapsulates an algorithm inside a class |
Template Method | Defer the exact steps of an algorithm to a subclass |
Visitor | Defines a new operation to a class without change |
Hello world!
Welcome to BhaskarChar.WordPress.com. This is your first post. Edit or delete it and start blogging!