Ticket T726514
Visible to All Users

Web - How to support case-insensitive URLs

created 6 years ago (modified 6 years ago)

How can I find a ModelView that is case-insensitive? FindModelView is case-sensitive.

Show previous comments (1)

    I am building my own CustomRouteManager for version 19.1. In GetViewShortcut I have to find the right ViewId. That wouldn't be a problem, but the urls are all lower case. Thus the ViewId is also written in lower case in ViewShortcut.
    Now my idea was to find the suitable IModelView and to read out the correct ViewId from it.

    https://github.com/DevExpress-Examples/friendly-url-sample/blob/master/VB/FriendlyUrlSample.Web/CustomRouteManager.vb

      This is the case when lower case is forced for all urls.
      routes.LowercaseUrls = True
      This is necessary in my project because I use XAF together with other websites. XAF is accessible via /admin/.

        BrowserHistoryMode = BrowserHistoryMode.FriendlyUrl

        Answers approved by DevExpress Support

        created 6 years ago (modified 6 years ago)

        Thank you for your clarification, Mario. In XAF, Contact_ListView and contact_ListView are two different valid view IDs. As a result, the FindModelView method should be case-sensitive. However, starting with version 19.1, you can create a custom IViewUrlManager to support case-insensitive URLs. For example, your CustomViewUrlManager may look like:

        C#
        using System; using System.Collections.Generic; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Web; namespace FriendlyUrlSample.Web { public class CustomViewUrlManager : IViewUrlManager { private IViewUrlManager innerViewUrlManager; Dictionary<string, string> viewIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); public CustomViewUrlManager() { innerViewUrlManager = new ViewUrlManager(); foreach(var view in WebApplication.Instance.Model.Views) { viewIds.Add(view.Id, view.Id); } } public string GetUrl(ViewShortcut shortcut, IDictionary<string, string> additionalParams = null) { return innerViewUrlManager.GetUrl(shortcut, additionalParams); } public ViewShortcut GetViewShortcut() { ViewShortcut shortcut = innerViewUrlManager.GetViewShortcut(); if(viewIds.ContainsKey(shortcut.ViewId)) { shortcut.ViewId = viewIds[shortcut.ViewId]; } return shortcut; } } }

        Please test this solution on your side to check if it provides you with the required behavior.

          Comments (2)

            Yes, you can go public.

            DevExpress Support Team 6 years ago

              Thank you, Mario!

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.