Pages

Tuesday, April 17, 2012

Elmah Error Loging Module and Handler for Asp.net

Introduction
            ELMAH is an open source project used to add error logging capabilities to an ASP.NET Web application. ELMAH essentially provides a means for logging and reporting unhandled exceptions in applications. I came across this very nifty tool while working with the MASS LEG team to create the Legislative Automated Workflow System (LAWS) application for the Massachusetts Legislature. We used ELMAH to uncover issues in the application that were producing unhandled and non-descriptive exceptions.  Using ELMAH, the dev team was able to use the stack trace of the exception to pinpoint and fix the problem. The following provides a brief description of how to set up ELMAH and enable & configure its error logging.
Link for tutorial:
Integrating ElMAH in asp.net is preety straight forward:
1. Download ELMAH and add the Elmah.dll assembly to your web application, 
2. Register ELMAH's HTTP Modules and Handler in Web.config,
3. Specify ELMAH's configuration options, and
4. Create the error log source infrastructure, if needed.

Follow instruction in tutorial, Your Final web config may look lik this:



After you change your web.Config add reference of elmah.dll to your Bin directory and create the table ELMAH_Error in sqlserver

You can execute the sqlserver.sql file in order to create table and store procedures.. and its done :)
you can see the logs by adding elmah.axd in root directory like
www.example.com/elmah.axd or localhost/something/elmah.axd
good luck

Tuesday, March 27, 2012

Vanity Url using Url Rewriting in asp.net 4.0

Url rewriting can be accomplish via two methods:
1.HTTP module 
2HTTP handler
let us discuss using HTTP handler:


Since SEO comes into consideration it becomes the part of web development. These days every website being developed should be optimized to some extent so it could get crawled by Search Engines.Its advisable that you should take care of your URL’s rather than showing them in a raw format make them readable by user as well SEO friendly.
URL is the important part that search engines want to take a look before they crawl the pages of your website. There are enormous open source libraries and ISAPI filter available that provides support to help you rewriting your URLs. The SEO and url rewriting is now taken into account and is introduced a supported extension for IIS 7.0/7.5 by providing URLRewriterExtension. But here we’re going to discuss how you can rewrite you URL in your Asp.net website with just 3 steps.

1. Create a Route path entry in RouteCollection
First of all add below code your to you Global.asax file. you can add as many route as you want to the RouteCollection object.

image




2. Create a class specific to the particular section that implements the IRouteHandler interface
to handle the incoming Route and receiving the data from the URL
 
image

3. Finally get into the Asp.net web form and process the request
span style="font-family: 'Courier New';">protected void Page_Load(object sender, EventArgs e)
 {
 int catid = Convert.ToInt32(HttpContext.Current.Items["catid"]);     
 var product = awe.Products.Where(item => item.ProductSubcategoryID == catid);             GridView1.DataSource = product;

 GridView1.DataBind(); 
}

sources: 
http://msdn.microsoft.com/en-us/library/ms972974
http://somenewkid.blogspot.com/2006/05/charlie-has-cool-urls-part-1.html

Download Source Code

Tuesday, January 31, 2012

Asp.net development server failed to start listening on port xxxx.

 I got the message:

Asp.net development server failed to start listening on port xxxx.
Error Message: only one usage of each socket address is normally permitted .

Search on net, people all think that if the port is not available, just change the port for the web development server and it will work. Based on this theory, I changed the port number of the ASP.NET web development server, and it worked for me. I typed the steps here…
Go to the Solution Explorer in Visual Studio, click on the web site application, hit ‘F4′ key to bring up the application’s property window. In this property window, set ‘Use Dynamic Port’ to ‘False’, and you will be able to set the Port number to a number other than the previous port number.
See this official MSDN document on how to change the port number for the ASP.NET development server:
http://msdn.microsoft.com/en-us/library/ms178109(VS.80).aspx

Wednesday, October 19, 2011

Query to find non unique column from a table

I have a users table that has over 10,000 registered users (from a database that I've inherited). The original code allows for multiple registrations with the same email address which I want to eliminate. 

Thursday, October 13, 2011

asp:XXXXX is not a known element. This can occur if there is a compilation error in the web site.

Problem occurred when I re-install Visual Stdio 2005...after digging for awhile i find the solution. Changing tag prefix did the job.
<webconfig

<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
change tagPrefix="asp" to tagPrefix="ajax" or whatever prefix you want. Then change your existing ajax control tags to use that prefix instead. E.g. <asp:UpdatePanel...> becomes <ajax:UpdatePanel...>