ASP.NET includes tracing functionality that can be used to track different issues in an application. It can be used to easily inspect errors that have occurred, check sessions IDs, cookie values, ViewState size, server variables plus a lot more.
The ASP.NET AJAX client script library also includes basic tracing functionality that can be used to write trace messages to a console window (that show up while debugging) or to the actual page. The client-side tracing functionality can also be used to dump values contained within a JSON object so that they are easily viewed. All of this client-side tracing functionality is exposed by the Sys.Debug class. An example of using it to write a trace message to the console and dump the contents of an Album object is shown next:
Adding calls to Sys.Debug.trace() will cause the trace information to be shown in the Visual Studio .NET 2005 console window while debugging, but the trace information won't be shown in the page. In cases where you'd like to see the output of different trace statements directly in the page you can add a textArea tag and give it an id of TraceConsole :
<--textarea id="TraceConsole" -->
Sunday, December 25, 2011
Monday, December 19, 2011
Permanent Redirections with Response.PermanentRedirect
To redirect a page request to another page ASP.NET ships with Response.Redirect() since the v1 that takes a string Url as the input parameter.
You will recall that this is not a permanent redirect, you know that to be able to make a permanent redirect you will have to do something like this
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", StringUrl);
ASP.NET 4.0 now ships with a Response.PermanentRedirect() helper method that redirects the user permanently to a new page. Watch Joe’s quick hit video to see it in action.
Fortunately we don't need to wait for .NET 4.0 to have a fancy method like above, we can with the help of C# Extension methods, create a helper method today.
For example take a look at this code
public static void PermanentRedirect(this HttpResponse response, string StringUrl) {
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", StringUrl);
}
Now if you do a Response. you will see the static helper method in the intellisense.
You will recall that this is not a permanent redirect, you know that to be able to make a permanent redirect you will have to do something like this
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", StringUrl);
ASP.NET 4.0 now ships with a Response.PermanentRedirect() helper method that redirects the user permanently to a new page. Watch Joe’s quick hit video to see it in action.
Fortunately we don't need to wait for .NET 4.0 to have a fancy method like above, we can with the help of C# Extension methods, create a helper method today.
For example take a look at this code
public static void PermanentRedirect(this HttpResponse response, string StringUrl) {
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", StringUrl);
}
Now if you do a Response. you will see the static helper method in the intellisense.
Wednesday, December 14, 2011
Dll referencing conflict between GAC and Bin
Few days ago, I was looking a issue faced by my colleague. He was trying to retrieve some values from Mysql db, using stored procedure. The application was layer down in different projects i.e. Data Access project for database communication and so on.
When he passed collection of parameter to data access, there was a weird error popsup i.e. (cannot cast MySql.Data.MysqlParameter to MySql.Data.MysqlParameter). I was amazed to see, whats going on. I double checked that the reference was added there.
After spending some time closely, I saw a dll hell type thing i.e. the Website had Mysql dll in the bin folder as well as in GAC and the data access referred it from GAC. As a result: the dll of different versions creating problem in type casting mysqlparameter collection from one project to another. I removed the dll from bin folder so that same GAC dll would be used in both projects and it started working.
Always add the project references cleanly to avoid this type of thing. I hope this post would be useful for you guys.
Happy Coding.....
When he passed collection of parameter to data access, there was a weird error popsup i.e. (cannot cast MySql.Data.MysqlParameter to MySql.Data.MysqlParameter). I was amazed to see, whats going on. I double checked that the reference was added there.
After spending some time closely, I saw a dll hell type thing i.e. the Website had Mysql dll in the bin folder as well as in GAC and the data access referred it from GAC. As a result: the dll of different versions creating problem in type casting mysqlparameter collection from one project to another. I removed the dll from bin folder so that same GAC dll would be used in both projects and it started working.
Always add the project references cleanly to avoid this type of thing. I hope this post would be useful for you guys.
Happy Coding.....
Wednesday, November 30, 2011
Using ASP.NET Session State in a Web Service
One of the most common challenges that Web developers encounter is maintaining state in the stateless world of HTTP. There have been a number of clever means used to get around the stateless issue, from reposting application data with each request, to using HTTP authentication to map requests to specific users, to using HTTP cookies to preserve the state of a series of requests. One particularly clever way of maintaining state that hides all the challenging work below is to simply use the Microsoft® ASP.NETSystem.Web.SessionState.HttpSessionState class. You can use the ASP.NET HttpSessionState class from a Web method just as you can from ASPX pages, but things work a little differently for Web methods.
For detail click here
Subscribe to:
Posts (Atom)