How do I handle the notify option using Asp.Net?

To handle correctly “notify” option you can do the following:

1)     add an {YourFileName}.aspx into your Asp.Net Web Application. Where {YourFileName} – is the name of your .aspx file.

2)     Put this code into {YourFileName}.aspx

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false"%>
<%@ Import Namespace="System.IO" %>
<script  runat="server">
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if(Request.HttpMethod=="POST")
        {
            var encodingXmlResult = Request.Form["xml"] ?? string.Empty;
            /*
            Your code goes here
            //parse and handle the XML
            var service=new CustomService();
            service.ParseAndHandleEncodingXml(encodingXmlResult);
           */
        }

} </script>

 

Please, note the ValidateRequest=”false” is required, because of the Asp.Net security  system  doesn’t let to post  xml by default.

If you are using Asp.Net  4, modify  your web.config file and add the following lines before the closing </configuration>

<location path="{PatthToYourFile}/{YourFileName}.aspx">
    <system.web>
        <httpRuntime requestValidationMode="2.0"/>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

 

Notificatons will come in the InputStream and not as a Request.Form.

The code:

using(var dataStream = HttpContext.Request.InputStream) {
    using(var reader = new StreamReader(dataStream) {
        string inputResult = reader.ReadToEnd(),
        encodingXmlResult = HttpUtility.UrlDecode(inputResult.Substring("xml=".Length));
        /* Your code goes here
        //parse and handle the XML
        var service=new CustomService();
        service.ParseAndHandleEncodingXml(encodingXmlResult);
        */
    }
}
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading...

edchelp