European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

European ASP.NET 4.5 Hosting - Amsterdam :: HTML 5 Input Types in ASP.NET 4.5

clock June 22, 2012 08:26 by author Scott

Microsoft has released developer previews for Visual Studio 2011 and .Net framework 4.5. There are lots of new features available in the developer preview. One of the most interested things for web developers is the support introduced for new HTML 5 form controls.

The following are the list of new controls available in HTML 5


- email

- url
- number
- range
- Date pickers (date, month, week, time, datetime, datetime-local)
- search
- color

Describing the functionality for these controls is not in the scope of this article. If you want to know about these controls, refer the below URLs


http://msdn.microsoft.com/en-us/magazine/hh547102.aspx


http://www.w3schools.com/html5/html5_form_input_types.asp


ASP.Net 4.5 introduced more possible values to the Text Mode attribute to cater the above requirements. Let us evaluate these. I have created a project in Visual Studio 2011 developer preview, and created a page named “controls.aspx”. In the page I placed on Text box control from the toolbox




Now select the control and go to the properties pane, look at the TextMode attribute.



Now you can see more options are added here than prior versions of ASP.Net. I just selected Email as TextMode. I added one button to submit my page. The screen shot of the page in Visual Studio 2011 designer is as follows



See the corresponding markup


<form id="form1" runat="server">
    <div>
       Enter your email:
       <asp:TextBox ID="TextBox1" runat="server" TextMode="Email"></asp:TextBox
     </div>
     <asp:Button ID="Button1" runat="server" Text="Submit" />
</form>


Now let me run this page, IE 9 do not have the support for new form fields. I browsed the page using Firefox and the page appears as below.



From the source of the rendered page, I saw the below markup for my email textbox

<input name="TextBox1" type="email" id="TextBox1" />

Try to enter an invalid email and you will see the browser will ask you to enter a valid one by default.



When rendered in non-supported browsers, these fields are behaving just as normal text boxes. So make sure you are using validation controls with these fields.


See the browser support compatability matrix with these controls with various browser vendors.




ASP.Net 4.5 introduced the support for these new form controls. You can build interactive forms using the newly added controls, keeping in mind that you need to validate the data for non-supported browsers.

 

 



European ASP.NET 4.5 Hosting - Amsterdam :: Asynchronous HTTPHandlers with ASP.NET 4.5

clock June 8, 2012 08:06 by author Scott

The working of Asynchronous Handler can be shown as



As we know if we need to create a normal custom HTTPHandler. We need to implement
IHTTPHandler interface and if we want to create a custom Asynchronous HTTPHandler, we need to implement IHttpAsyncHandler.

In this post, I will be discussing, How we can write Asynchronous HTTPHandlers with the help of new features introduced in .NET 4.5 framework.


In the example, I’ll create an asynchronous HTTPHandler with the help of asp.net 4.5 that downloads rss feed.


To create Asynchronous HTTPHandler in asp.net 4.5, we need to implement the method
ProcessRequestAsync of new abstract class HttpTaskAsyncHandler that got newly introduced.

For that I created a class library named
AsyncHandlerLibrary , which has a Handler class CustomAsyncHandler which implements HttpTaskAsyncHandler.

So the class CustomAsyncHandler will be as


public class CustomAsyncHandler : HttpTaskAsyncHandler
 {

    public override async Task ProcessRequestAsync(HttpContext context)
    {
        string url = context.Request.QueryString["rssfeedURL"];
        if (string.IsNullOrWhiteSpace(url))
        {
           context.Response.Write("Rss feed URL is not provided");
        }
        WebClient webClient = new WebClient();

        //It starts downloading the rss asynchronously and the asp,net thread become free
        //and become available in threadpool
        //once the the it load the rssfeed loading completes it get assigned to another ASP.NET thread from the threadpool
        var rssfeed = await
            webClient.DownloadStringTaskAsync(url);

        // Writing the rss on the screen
        context.Response.Write(rssfeed);
    }

     public override bool IsReusable
     {
         get { return true; }
     }

     public override void ProcessRequest(HttpContext context)
     {
         throw new Exception("The ProcessRequest method has no implementation.");
     }

}

Now if you see the above code, I have implemented
ProcessRequestAsync , in which I read the rss url from query string. And asynchronously downloaded the rss feed and later wrote it in response.

Now you can see, with help of new keywords async keyword and await operator of .NET 4.5, it is extremely easy to write asynchronous code. It also got ensured that same can be used in asp.net with the introduction of new APIs.

Now build the project and add the reference in your web application. Also add this in your web.config file as

<system.webServer>
  <handlers>
     <add name="myHandler" verb="*" path="*.rss" type="AsyncHandlerLibrary.CustomAsyncHandler"/>
  </handlers>
</system.webServer>

Then run your application.
Now you can see it has never been so easy to write Asynchronous HTTPHandler. Now enjoy coding with ASP.NET 4.5.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in