Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Application.AuthenticateRequestArgs have changed

Application.AuthenticateRequestArgs have changed

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

We had a custom development that stopped working as of 9.9 because the args of the Application.AuthenticateRequestArgs have changed.

 

public override void OnNotify(string notification, NotificationArgs args)
    {
      var authArgs = (Dynamicweb.Notifications.Standard.Application.AuthenticateRequestArgs)args;
      var app = authArgs.Application;
      if (!string.IsNullOrEmpty(app.Request.AppRelativeCurrentExecutionFilePath) && (app.Request.AppRelativeCurrentExecutionFilePath.ToLower().Contains("stylesbundle")|| app.Request.AppRelativeCurrentExecutionFilePath.ToLower().Contains("scriptsbundle")))
      {
        authArgs.Handled = true;
      }
    }

 

The problem is that args.Application.Request no longer exists. Is there a recommended alternative?

 

Best Regards,

Nuno Aguiar

 

Is there a


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Nuno,

We are in the process of moving/removing dependencies on System.Web and it seems that we have made some breaking changes here.
The Application property now returns a Dynamicweb.Environment.IApplication instead of System.Web.HttpApplication.

If you need full access to HttpApplication and HttpRequest from System.Web then you can use System.Web.HttpContext.Current.ApplicationInstance and System.Web.HttpContext.Current.Request. Alternatively you can use our abstractions Dynamicweb.Context.Current.Application and Dynamicweb.Context.Current.Request

Sorry about the inconvenience.

Best regards,
Morten

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

Ok, thanks. I was able to move past that, but I have a YSOD https://www.screencast.com/t/3I2ZYwaL1YS9 associated with the Args

 

Do you have a suggestion on the best way to change this code

 

using Dynamicweb.Extensibility.Notifications;

namespace Dna.Optimizer
{
  /// <summary>
  /// Bypasses Dynamicweb's routing for our own requests.
  /// </summary>
  [Subscribe(Dynamicweb.Notifications.Standard.Application.AuthenticateRequest)]
  public class SkipBundleRoutes : NotificationSubscriber
  {
    /// <summary>
    /// Sets Handled = true for requests that are meant for the bundler (i.e. stylesbundle and scriptsbundle).
    /// </summary>
    public override void OnNotify(string notification, NotificationArgs args)
    {
      var authArgs = (Dynamicweb.Notifications.Standard.Application.AuthenticateRequestArgs)args;
      var filepath = authArgs.Application.Request.ApplicationPath;
      if (!string.IsNullOrEmpty(filepath) && (filepath.ToLower().Contains("stylesbundle")|| filepath.ToLower().Contains("scriptsbundle")))
      {
        authArgs.Handled = true;
      }
    }
  }
}

 

In theory I could do var filepath = Dynamicweb.Context.Current.Request.Path;

This prevents me from having to use the Args, but then I don't know how to overcome the Handled property, which is there to let DW know that the request is being handled by a third party.

 

Any thoughts?

 

Best Regards,

Nuno Aguiar

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Nuno,

The exception is related to the line where you get the request path, because the Application property now returns Dynamicweb.Environment.IApplication instead of System.Web.HttpApplication:

var filepath = authArgs.Application.Request.ApplicationPath;

As you mentioned that part can be replaced with this:

var filepath = Dynamicweb.Context.Current.Request.Path;

You still need to use the args to set Handled = true. It is a separate property and it works as before.

namespace Dna.Optimizer
{
    /// <summary>
    /// Bypasses Dynamicweb's routing for our own requests.
    /// </summary>
    [Subscribe(Dynamicweb.Notifications.Standard.Application.AuthenticateRequest)]
    public class SkipBundleRoutes : NotificationSubscriber
    {
        /// <summary>
        /// Sets Handled = true for requests that are meant for the bundler (i.e. stylesbundle and scriptsbundle).
        /// </summary>
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var authArgs = (Dynamicweb.Notifications.Standard.Application.AuthenticateRequestArgs)args;
            var filepath = Dynamicweb.Context.Current.Request.Path;
            if (!string.IsNullOrEmpty(filepath) && (filepath.ToLower().Contains("stylesbundle") || filepath.ToLower().Contains("scriptsbundle")))
            {
                authArgs.Handled = true;
            }
        }
    }
}

/Morten 

Votes for this answer: 2
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

That's right. I made the change you suggested and it's working for me again.

 

Thanks,

Nuno Aguiar

 

You must be logged in to post in the forum