Development World

New Development Technologies , Computer Last News , Tips & Tricks , UI , CSS , HTML , ASP , C# , .net Framework , Patterns & Practices & etc

How to: Create Synchronous HTTP Handlers
hour ٢:٥۸ ‎ب.ظ day ۱۳۸٧/۳/۸  

This topic illustrates the code for an HTTP handler that performs synchronous processing of requests for resources in an ASP.NET application whose URL ends with .sample. The code example illustrates the following:

  • The code for an HTTP handler class. The class must implement the ProcessRequest method and the IsReusable property.

  • The elements that are required in a Web.config file to register the handler and map the .sample file name extension to it.

  • In Internet Information Services (IIS), how to map the .sample file name extension to ASP.NET.

NoteNote

The ASP.NET Development Server will serve the request for the new resource after the configuration file is changed to include a reference to the new handler. To enable IIS to serve the request, see the procedure below.

When users request a resource whose URL ends in .sample, the Web server forwards the request to ASP.NET. ASP.NET then calls the HTTP handler, which returns a response. The response is created dynamically by the handler; there is no need for a file with the file name extension .sample to exist. For more information about how ASP.NET interacts with the Web server, see ASP.NET Life Cycle.

To create the custom HelloWorldHandler HTTP handler class

  1. In your Web site's App_Code directory, create a class named HelloWorldHandler.

  2. Add the following code to your class file.

    using System.Web;
    public class HelloWorldHandler : IHttpHandler
    {
        public HelloWorldHandler()
        {
        }
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest Request = context.Request;
            HttpResponse Response = context.Response;
            // This handler is called whenever a file ending
            // in .sample is requested. A file with that extension
            // does not need to exist.
            Response.Write("<html>");
            Response.Write("<body>");
            Response.Write("<h1>Hello from a synchronous custom HTTP handler.</h1>");
            Response.Write("</body>");
            Response.Write("</html>");
        }
        public bool IsReusable
        {
            // To enable pooling, return true here.
            // This keeps the handler in memory.
            get { return false; }
        }
    }

Registering a Custom HTTP Handler

After you have created the custom HTTP handler class, you must register it in the application's Web.config file. This allows ASP.NET to find the handler when ASP.NET receives requests made to resources whose URL ends with .sample.

To register a custom HTTP handler in the Web.config file

  1. Add a Web.config file to your Web site if one does not already exist.

  2. Add the following highlighted element to your Web.config file.

    <configuration>
        <system.web>
            <httpHandlers>
                <add verb="*" path="*.sample" 
                      type="HelloWorldHandler"/>
            </httpHandlers>
        </system.web>
    </configuration>

    The code registers your custom handler by class name and maps the .sample file name extension to that handler.

Configuring IIS 6.0 for an HTTP Handler Extension

IIS passes requests for only certain file types to ASP.NET to service. By default, files with file name extensions such as .aspx, .ascx, .asmx, are already mapped in IIS 6.0 to the ASP.NET ISAPI extension (Aspnet_isapi.dll). However, if you want ASP.NET to handle custom URL extensions, you must map the extensions in IIS. For more information, see ASP.NET Life Cycle.

To map the .sample file name extension to ASP.NET in IIS 6.0

  1. Open Internet Information Services (IIS) Manager.

  2. Right-click the name of your application, and then click Properties.

    Note

    For instructions for creating an ASP.NET application, see How to: Create and Configure Local ASP.NET Web Sites in IIS.

  3. Click the Virtual Directory tab, and then click Configuration.

  4. On the Mappings tab, click Add.

    The Add/Edit Application Extension Mapping dialog box is displayed.

  5. In the Executable box, type or browse to the file Aspnet_isapi.dll. By default, the file is in the following location.

    %windows%\Microsoft.NET\Framework\version\
    Note

    You can get the complete path and file name from other mappings, such as the mapping to .aspx files.

  6. In the Extension box, type .sample.

  7. Clear the Verify that file exists check box.

  8. Click OK and then close IIS Manager.

Testing the Custom HTTP Handler

After you have created and registered your custom HTTP handler, you can test it by requesting a resource that has a .sample file name extension.

To test your custom HTTP handler

  • In your browser, enter a URL that points to your Web application and that ends in .sample, such as the following:

    http://localhost/SampleApplication/test.sample

    The text defined in the HelloWorldHandler class is displayed.


Reference : MSDN

Keywords :http handler ،Keywords :iis ،Keywords :visual studio ،Keywords :fix error
 
VS 2008 Web Development Hot-Fix Roll-Up Available
hour ۱:٤٢ ‎ب.ظ day ۱۳۸٧/٢/۱٦  
 

One of the things we are trying to do with VS 2008 is to more frequently release public patches that roll-up bug-fixes of commonly reported problems.  Today we are shipping a hot-fix roll-up that addresses several issues that we've seen reported with VS 2008 and Visual Web Developer Express 2008 web scenarios.

Hot Fix Details

You can download this hot-fix roll-up for free here (it is a 2.6MB download).  Below is a list of the issues it fixes:

HTML Source view performance

 

  • Source editor freezes for a few seconds when typing in a page with a custom control that has more than two levels of sub-properties.
  • “View Code” right-click context menu command takes a long time to appear with web application projects.
  • Visual Studio has very slow behavior when opening large HTML documents.
  • Visual Studio has responsiveness issues when working with big HTML files with certain markup.
  • The Tab/Shift-Tab (Indent/Un-indent) operation is slow with large HTML selections.

 

Design view performance

 

  • Slow typing in design view with certain page markup configurations.

HTML editing

  • Quotes are not inserted after Class or CssClass attribute even when the option is enabled.
  • Visual Studio crashes when ServiceReference element points back to the current web page.

JavaScript editing

 

  • When opening a JavaScript file, colorization of the client script is sometimes delayed several seconds.
  • JavaScript IntelliSense does not work if an empty string property is encountered before the current line of editing.
  • JavaScript IntelliSense does not work when jQuery is used.

Web Site build performance

 

  • Build is very slow when Bin folder contains large number of assemblies and .refresh files with web-site projects.

Installation Notes

For more information on how to download and install the above patch, please read this blog post here.  In particular, if you are using Windows Vista with UAC enabled, make sure to extract the patch to a directory other than "c:\" (otherwise you'll see an access denied error).

To verify that this hot-fix patch successfully installed, launch VS 2008 and select the Help->About menu item.  Make sure that there is an entry that says ‘Hotfix for Microsoft Visual Studio Team System 2008 Team Suite – ENU (KB946581)’. 

If you ever want to remove the patch, go to Control Panel -> Add/Remove Programs and select “Hotfix for Microsoft Visual Studio 2008 – KB946581” under Microsoft Visual Studio 2008 (or Visual Web Developer Express 2008) and click “Remove".

Summary

Obviously it goes without saying that we would have liked to have shipped without any bugs.  Hopefully this hot-fix enables you to quickly solve them if you are encountering them.  Thank you to those who helped us identify the causes of these issues, as well as to the group of customers who have helped us verify the above fixes the last few weeks.

Note: If you do encounter issues with VS 2008 features for web development in the future, I recommend always asking for help in the VS 2008 Forum on http://www.asp.net/.  The VS Web Tools team actively monitors this forum and can provide help.

Hope this helps,

Reference :

 http://weblogs.asp.net/scottgu/archive/2008/02/08/vs-2008-web-development-hot-fix-roll-up-available.aspx
 

Download : https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10826


Keywords :webdev ،Keywords :visual studio ،Keywords :hotfix ،Keywords :recommanded by me
 
Unable to connect to Visual Studio's Localhost Web Server
hour ۱٢:۱٤ ‎ب.ظ day ۱۳۸٧/٢/٥  
Screwing up an installation is so easy! I realized it when I was working on an issue today and had to uninstall the .NET Framework (that's different story ;o). I used my Control Panel and uninstalled it, but I was not done yet! I wanted to wipe out all traces of .NET 2.0 from my box and I deleted the C:\WINNT\Microsoft.NET\Framework\v2.0.50727 folder. Then I simply re-installed it and found that everything was working fine except the projects which were being accessed through FileSystem. I was not able to debug those projects at all... Even a CTRL+F5 wouldn't work!!

Here is the error message which I got...

---------------------------
Microsoft Visual Studio
---------------------------
Unable to connect to Visual Studio's Localhost Web Server
---------------------------
OK  
---------------------------

Very soon, I found that there is a file called WebDev.WebServer.exe which was located in C:\WINNT\Microsoft.NET\Framework\v2.0.50727 folder and it was gone since I deleted the folder itself! Aahh... too late... But I was really happy when I found that when I copied the file WebDev.WebServer.exe from one of my colleague's box, it worked absolutely fine :o) And that just saved me a lot of time!

I would have hated myself, if I had to re-install the VS 2005 just because of a simple mistake.

The point to be noted here are...
1) Don't use Shift+Del to delete important folders. It is better to rename it ;o) (as if you didn't know already!)
2) In case you do the same mistake as I did... find a person who has the file, and Copy + Paste!!
3) It seems like VS2005 installation puts the file (WebDev.WebServer.exe) in the Framework folder. Take good care of it :o)


Keywords :.net framework 2.0 ،Keywords :iis ،Keywords :webdev ،Keywords :visual studio