Skip to main content

Posts

Showing posts from 2008

How to call web service in javascript using ASP.Net AJAX?

I wanted to call a web service that is internal to my asp.net web site project in my javascript code and I wanted to call it using the ASP.Net AJAX instead of the usual XMLHttpRequest stuff. So here is what I found. In-order to acheive this lets create a simple web site project and add a very basic service. Lets name it as HelloService (HelloService.asmx). Add a simple web method GetMessage which will accept an integer input and return a string type.  Your HelloService.asmx.cs should look like this. using System.Web.Script.Services; namespace MyServices {     [WebService(Namespace = "http://tempuri.org/")]     [WebServiceBinding(ConformsTo =      WsiProfiles.BasicProfile1_1)]         // To allow this Web Service to be called from script,     // using ASP.NET AJAX.     [ScriptService]         public class HelloService : Syste...

How to use a custom config file?

Recently I was wondering how to use custom configuration files in my application. So here it is all about custom configuration file First of all let me clarify what I mean by custom configuration files? For me it was simply about using customfile.config instead of the usual app.config and or web.config. In-order to use customfile.config instead of app.config in an application lets create a simple console application. After you have created a simple console application right click the project in solution explorer window and click add new item. From the list of options available select the Application Configuration File. Now rename the app.config name to customfile.config and click ok. Open the customfile.config. <?xml version="1.0" encoding="utf-8" ?> <configuration> </configuration> Lets add some configuration elements that are most common to our config files. <?xml version="1.0" encoding="utf-8" ?> ...

URL Rewriting

When I first ventured into this topic I thought this would be pretty straight forward but then being in software field I should have known better. Nothing is as simple as it sounds. So here we go URL re-writing in ASP.Net. What URL re-writing means is that you intercept an incoming web request in your web application and then redirect the web request to a different web resource in your web application. Now this is not done simply using Response.Redirect or Server.Redirect. There are many reasons why you would choose to do URL re-writing and the major ones could be - You want your urls to be search engine friendly. Your website has undergone restructuring or you expect the folders to be moved arround later. You want your urls to be user friendly (as in easier to remember). Any web request when it enters the ASP.Net engine an HTTPContext object is created and assigned to it and then it goes through a series of HTTPModules finally hitting a HTTPHandler. The HTTPContext object provides a m...

When to use Viewstate, Session, and Cache?

ViewState is used to manage asp.net server side controls state accross page postbacks. We can always store our own custom information into the viewstate. While storing custom information note should be made of the size of the viewstate as it impacts the page rendering time at the client end. Session is used to manage information for a particular user session. Any information that is needed with in a particular user's session can be stored here. Caching is used in asp.net to store objects in memory that require extensive server resources to create. You can establish an expiration policy with this. As a general rule of thumb - You use ViewState to store small amounts of data that is needed within the same page. You use Session to store data that is needed within the same user session. You can use data caching to store data that is needed accross user sessions through out the application.