sachatrauwaen / OpenUrlRewriter

Open Url Rewriter for DNN (DotNetNuke)
Other
13 stars 8 forks source link

Lot of event errors log (UrlRewriter.UrlRuleConfig:GetConfig Failed) #18

Open Scippy opened 4 years ago

Scippy commented 4 years ago

Hi, looking at event log I can see a lot of errors log from UrlRewriter.UrlRuleConfig: GetConfig whit error message "Null object cannot be converted to a value type." Looking moore deep it look something linked to Ventrian PA Open Url Rewrite provider but with exception fired to OpenUrlRewriter. So I decided to debug the code to find where the problem could be. The problem is on AddUrlRule in UrlRuleController.cs Here is defined the function AddUrlRule with DotNetNuke.Data.DataProvider.Instance().ExecuteScalarDB call The problem is that it can't be converted to an Int32, as integers are value types and cannot be null. Either check the return value for DbNull and return a default value from your data layer, or check your query and database to ensure that a null will not be returned. This fired all exceptions. There are much ways to fix this, below my solution:

public static int AddUrlRule(UrlRuleInfo objUrlRule)
        {
            object result = DotNetNuke.Data.DataProvider.Instance().ExecuteScalar(ModuleQualifier + "AddUrlRule",
                                          objUrlRule.DateTime,
                                          objUrlRule.UserId,
                                          objUrlRule.RuleType,
                                          GetNull(objUrlRule.CultureCode),
                                          objUrlRule.PortalId,
                                          GetNull(objUrlRule.TabId),
                                          GetNull(objUrlRule.Parameters),
                                          objUrlRule.RemoveTab,
                                          objUrlRule.RuleAction,
                                          GetNull(objUrlRule.Url),
                                          GetNull(objUrlRule.RedirectDestination),
                                          GetNull(objUrlRule.RedirectStatus)
                                        );
            if (result == DBNull.Value)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(result);
            }

        }

Please @sachatrauwaen if you can fix on the next release. Thanks.

Scippy commented 4 years ago

Also evidence that to make all work fine is needed to compile the source code with DNN71 directive