Navigation: Clarion.Net (Clarion#) > Clarion.NET FAQs/Troubleshooting > WebForms >====== ASHX Page Support ====== | |
Today a typical web application is not only about serving HTML to browsers, but also serving XML and other types of content. An ASHX page handler (the default extension assigned by Microsoft) can be used to perform this operation.
To add an ASHX generic handler in Clarion.NET:
1.Open your Website project. In the Solution Explorer, right-click on the Project node and choose Add New Item from the popup menu.
This will open the Add New Item dialog box.
2.Select the Generic Handler item, and you will get a new ASHX file with some default code in it.
<;%@ WebHandler Language=“Clarion.NET” Class=“ASP.Handler1” %>
MEMBER('')
NAMESPACE ASP
USING System
USING System.Web
Handler1 CLASS(IHttpHandler), TYPE, PARTIAL
ProcessRequest PROCEDURE(HttpContext context), PUBLIC
IsReusable PROPERTY, BOOL, PUBLIC
INLINE
GETTER
CODE
RETURN FALSE;
SETTER
CODE
END
END
Handler1.ProcessRequest PROCEDURE(HttpContext context)
CODE
context.Response.ContentType = 'text/plain'
context.Response.Write('Hello World')
In the above code the only change needed was to line number 1. It is created initially as:
<;%@ WebHandler Language=“Clarion.NET” Class=“Handler” %>
3.Add the namespace and set the class name to its correct name (you can accept the ASHX file default name Handler1.ASHX), changed line number 1 to read as follows:
<;%@ WebHandler Language=“Clarion.NET” Class=“ASP.Handler1” %>
Testing the ASHX generic handler in Clarion.NET:
To test the ASHX handler, you can use urlMappings.
Add the following code to your web.config file:
<;system.web>
<;urlMappings enabled=“true”>
<;add url=“~/Default.aspx” mappedUrl=“~/Handler1.ashx”/>
<;/urlMappings>
Now run your web site and it will get redirected to your ASHX code.