Dynamicweb 8 Documentation
BeginRequest Field
Example 

Application begin request notification. Occurs when application process the request
Syntax
'Declaration
 
Public Const BeginRequest As String
public const string BeginRequest
Example
Overriding the application begin request notification in DynamicwebOverriding the application begin request notification in Dynamicweb
namespace Dynamicweb.Examples.CSharp.Notifications.Standard
{
    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Application.BeginRequest)]
    public class ApplicationBeginRequestObserver : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            if (args == null)
                return;

            if (!(args is Dynamicweb.Notifications.Standard.Application.BeginRequestArgs))
                return;

            Dynamicweb.Notifications.Standard.Application.BeginRequestArgs item = (Dynamicweb.Notifications.Standard.Application.BeginRequestArgs)args;
            System.Web.HttpApplication app = (System.Web.HttpApplication)item.sender;

            if (app.Context.Request.Cookies == null || app.Context.Request.Cookies.Count == 0)
                return;

            const string name = "my-custom-cookie";

            //Adding cookie
            System.Web.HttpCookie cookie = app.Context.Request.Cookies[name];
            if (cookie == null)
                app.Context.Response.Cookies.Add(new System.Web.HttpCookie(name, "hello!"));

        }
    }
}
Namespace Notifications.Standard
    <Extensibility.Subscribe(Global.Dynamicweb.Notifications.Standard.Application.BeginRequest)> _
    Public Class ApplicationBeginRequestObserver
        Inherits Global.Dynamicweb.Extensibility.NotificationSubscriber

        Public Overrides Sub OnNotify(ByVal notification As String, ByVal args As Global.Dynamicweb.Extensibility.NotificationArgs)
            If args Is Nothing Then
                Return
            End If

            If Not (TypeOf args Is Global.Dynamicweb.Notifications.Standard.Application.BeginRequestArgs) Then
                Return
            End If

            Dim item As Global.Dynamicweb.Notifications.Standard.Application.BeginRequestArgs = DirectCast(args, Global.Dynamicweb.Notifications.Standard.Application.BeginRequestArgs)
            Dim app As System.Web.HttpApplication = DirectCast(item.sender, System.Web.HttpApplication)

            If app.Context.Request.Cookies Is Nothing OrElse app.Context.Request.Cookies.Count = 0 Then
                Return
            End If

            Const name As String = "my-custom-cookie"

            'Adding cookie
            Dim cookie As System.Web.HttpCookie = app.Context.Request.Cookies(name)
            If cookie Is Nothing Then
                app.Context.Response.Cookies.Add(New System.Web.HttpCookie(name, "hello!"))
            End If
        End Sub
    End Class
End Namespace
Remarks
Event occurs when process the method Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) in Global.asax. The passed NotificationArgs is Dynamicweb.Notifications.Standard.Application.BeginRequestArgs
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Standard.Application Class
Standard.Application Members

Send Feedback