Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set mobile view cookie name in root web.config #4064

Merged
merged 18 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions DNN Platform/Library/Entities/Urls/FriendlyUrlController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Entities.Urls
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
Expand All @@ -30,9 +31,12 @@ public class FriendlyUrlController
private const string DisableMobileRedirectQueryStringName = "nomo";

// google uses the same name nomo=1 means do not redirect to mobile
private const string MobileViewSiteCookieName = "dnn_IsMobile";
private const string DisableMobileViewCookieName = "dnn_NoMobile";
// set the web.config AppSettings for the mobile view cookie name
private static readonly string MobileViewSiteCookieName = ConfigurationManager.AppSettings[name: "MobileViewSiteCookieName"] ?? "dnn_IsMobile";
private static readonly string DisableMobileViewCookieName = ConfigurationManager.AppSettings[name: "DisableMobileViewSiteCookieName"] ?? "dnn_NoMobile";


// <summary>Gets the Friendly URL Settings for the given portal.</summary>
public static FriendlyUrlSettings GetCurrentSettings(int portalId)
{
return new FriendlyUrlSettings(portalId);
Expand Down Expand Up @@ -926,6 +930,7 @@ internal static bool CanUseMobileDevice(HttpRequest request, HttpResponse respon
// no, can't do it
canUseMobileDevice = false;
var cookie = new HttpCookie(DisableMobileViewCookieName)

{
Path = !string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/",
};
Expand All @@ -935,10 +940,12 @@ internal static bool CanUseMobileDevice(HttpRequest request, HttpResponse respon
{
// check for disable mobile view cookie name
var cookie = request.Cookies[DisableMobileViewCookieName];

if (cookie != null)
{
// if exists, expire cookie to allow redirect
cookie = new HttpCookie(DisableMobileViewCookieName)

{
Expires = DateTime.Now.AddMinutes(-1),
Path = !string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/",
Expand All @@ -959,6 +966,7 @@ internal static bool CanUseMobileDevice(HttpRequest request, HttpResponse respon
{
// look for disable mobile view cookie
var cookie = request.Cookies[DisableMobileViewCookieName];

if (cookie != null)
{
canUseMobileDevice = false;
Expand Down Expand Up @@ -1010,7 +1018,8 @@ private static void CheckCharsForReplace(FriendlyUrlOptions options, ref string
return;
}

if (ch != " ") // if not replacing spaces, which are implied
// if not replacing spaces, which are implied
if (ch != " ")
{
replacedUnwantedChars = true;
}
Expand All @@ -1037,7 +1046,8 @@ private static bool ValidateUrl(string url, int validateUrlForTabId, PortalSetti
isUnique = tabId == -1 || tabId == validateUrlForTabId;
}

if (isUnique) // check whether have a tab which use the url.
// check whether have a tab which use the url.
if (isUnique)
{
var friendlyUrlSettings = GetCurrentSettings(settings.PortalId);
var tabs = TabController.Instance.GetTabsByPortal(settings.PortalId).AsList();
Expand Down
9 changes: 9 additions & 0 deletions DNN Platform/Website/Install/Config/09.07.02.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<configuration>
<nodes configfile="Web.config">
<!-- Add mobile view cookie names setting-->
<node path="/configuration/appSettings" action="update" key="key" collision="ignore">
<add key="MobileViewSiteCookieName" value="dnn_IsMobile" />
<add key="DisableMobileViewSiteCookieName" value="dnn_NoMobile" />
</node>
</nodes>
</configuration>
2 changes: 2 additions & 0 deletions DNN Platform/Website/development.config
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<add key="loginUrl" value="~/Login.aspx" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="ImprovementProgram.Endpoint" value="https://dev.dnnapi.com/beacon" />
<add key="MobileViewSiteCookieName" value="dnn_IsMobile" />
<add key="DisableMobileViewSiteCookieName" value="dnn_NoMobile" />
</appSettings>

<system.web.webPages.razor>
Expand Down
2 changes: 2 additions & 0 deletions DNN Platform/Website/release.config
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<add key="loginUrl" value="~/Login.aspx" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="ImprovementProgram.Endpoint" value="https://dnnapi.com/beacon" />
<add key="MobileViewSiteCookieName" value="dnn_IsMobile" />
<add key="DisableMobileViewSiteCookieName" value="dnn_NoMobile" />
</appSettings>

<system.web.webPages.razor>
Expand Down