• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Forums

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 17 Apr 2019 08:52 AM by  JoshGrew
UriFormatException
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Lukasz Kalita



New Member


Posts:1
New Member


--
10 Apr 2019 06:46 AM
    Hello,

    We are using Your library FiftyOne.Foundation v 3.2.8.1 in our MVC project (.Net 4.6.1).
    Can You please help us figure out what might cause following exception ?
    We tried to put exceptions filters(FilterAttribute, IExceptionFilter) and also log stuff in Application_Error method in Global.asax but nothing catches that error.
    Any ideas how to reproduce it ?

    Exception type: UriFormatException

    Exception message: Invalid URI: The hostname could not be parsed.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Web.Util.UriUtil.BuildUriImpl(String scheme, String serverName, String port, String path, String queryString, Boolean useLegacyRequestUrlGeneration)
    at System.Web.HttpRequest.BuildUrl(Func`1 pathAccessor)
    at System.Web.HttpRequest.get_Url()
    at FiftyOne.Foundation.Mobile.Redirection.RedirectModule.OnBeginRequest(Object sender, EventArgs e)
    at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


    And our config:


    <?xml version="1.0"?>
    <configuration>
    <!-- These configuration sections tell .NET how to handle the FiftyOne.Foundation.Mobile
    configuration settings further down the web.config file -->
    <configSections>
    <sectionGroup name="fiftyOne">
    <section name="log" type="FiftyOne.Foundation.Mobile.Configuration.LogSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
    <section name="redirect" type="FiftyOne.Foundation.Mobile.Configuration.RedirectSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
    <section name="detection" type="FiftyOne.Foundation.Mobile.Detection.Configuration.DetectionSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
    <section name="imageOptimisation" type="FiftyOne.Foundation.Mobile.Configuration.ImageOptimisationSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
    </sectionGroup>
    </configSections>
    <fiftyOne>

    <!--<redirect> element controls how requests from mobile devices are handled.
    mobileHomePageUrl Previously mobileRedirectUrl under the mobile/toolkit element.
    A url to direct mobile devices to instead of the normal web sites
    landing page. (Optional)
    firstRequestOnly If set to true only the first request received by the web site is
    redirected to the mobileUrl when the site is accessed from a mobile
    device. (Optional – defaults to true)
    timeout The number of minutes of inactivity that should occur before the
    requesting device should be treated as making a new request to the
    web site for the purposes of redirection. If the session is available
    the session timeout will be used and override this value. (Optional
    -defaults to 20 minutes)
    devicesFile A file used to store the details of devices that have previously
    accessed the web site to determine if they're making a subsequent
    request. Needed to ensure multiple worker processes have a consistent
    view of previous activity. (Optional – random behaviour will be
    experienced if not specified on web sites with more than one worker
    processes). In Windows Azure this value becomes the name of devices
    cloud table that will be used instead of a file.
    mobilePagesRegex A regular expression that when applied to the current request Path
    (context.Request.AppRelativeCurrentExecutionFilePath) or the requesting
    Urlwill return true if it should be considered a mobile page. Use
    this attribute to tell redirection about mobile pages derived from base
    classes such as System.Web.UI.Page. Redirection needs to be aware of
    mobile pages so that requests to these pages can be ignored. Any page
    that derives from System.Web.UI.MobileControls.MobilePage will
    automatically be treated as a mobile page irrespective of this
    attribute. (Optional)
    originalUrlAsQueryString
    If set to true the redirected URL will have the original requesting Url
    encoded and included as the origUrl query string parameter in the
    redirected Url. This will enable the mobile home page to determine the
    original requested resource providing the option to display a mobile
    friendly version. (Optional – defaults to false)
    locations/location Provides details of different locations requests can be directed to based
    on the values of defined properties associated with the device or request.
    (Optional)
    name A unique identifier for the location. Used for debugging in the log file.(Mandatory)
    url the URL of the redirect location to use if all the properties in the
    collection match. (Mandatory)
    matchExpression can be used to provide a regular expression which will take the requesting
    URL as input match segments to be used in place of numeric parameters contained
    within {} in the url attribute. (Optional)
    The location element contains a collection of criteria that all need to match
    for the location to be used. Two attributes must be specified with each entry.
    property the property of HttpRequest, HttpRequest.Browser or 51Degrees.mobi property to
    use when evaluating the matchExpression attribute. (Mandatory)
    matchExpression a regular expression used to evaluate the value of the property. (Mandatory)
    -->

    <!-- <redirect devicesFile="" timeout="20" firstRequestOnly="true"
    originalUrlAsQueryString="false" mobileHomePageUrl="~/Mobile/Default.aspx"
    mobilePagesRegex="/(Mobile|Tablet)/">
    <locations>
    <clear />
    <location name="noredirect" url="" matchExpression="" enabled="true">
    <add property="Url" matchExpression="[&|\?]noredirect" enabled="true" />
    </location>
    <location name="Mobile" url="~/Mobile/Default.aspx" matchExpression=""
    enabled="true">
    <add property="IsMobile" matchExpression="True" enabled="true" />
    <add property="IsTablet" matchExpression="False" enabled="true" />
    </location>
    <location name="Tablet" url="~/Tablet/Default.aspx" matchExpression=""
    enabled="true">
    <add property="IsTablet" matchExpression="True" enabled="true" />
    </location>
    </locations>
    </redirect>
    -->
    <!--<log> element controls where and how much information should be recorded in the log.
    logFile The location of the log file in ASP.NET or the name of the log table in
    Windows Azure. (Mandatory)
    logLevel Values include Debug|Info|Warn|Fatal and control the level of information
    logged. Defaults to Fatal if not specified. (Optional)-->

    <log logFile="~/App_Data/Log.txt" logLevel="Warn"/>

    <!--<detection> element controls where the data files used are provided.
    If a Premium/Ultimate Data license key is present in a file with the extension .lic in the bin
    folder, or provided in the FiftyOne.Foundation.Mobile.Detection.Constants.PremiumLicenceKey
    constant the binaryFilePath attribute of the detection element must be provided and the worker
    process must have modify access to the file to enable automatic updates to be downloaded.

    enabled Controls whether device detection is enabled. Defaults to true. (Optional)
    autoUpdate When set to true enables automatic updating of device data when licence keys
    are provided. Defaults to true. (Optional)
    binaryFilePath Path to the binary data file. (Optional - Lite / Mandatory - Premium / Enterprise)
    shareUsage Set to true to share usage information with 51Degrees.mobi. Read the Usage Data FAQ
    to learn more. Defaults to True if not specified. (Optional)
    memoryMode True if the data set should be loaded into memory. Detection performance will be
    significantly faster at the expense of a longer startup time and increased memory
    usage. Defaults to False if not specified. (Optional)
    bandwidthMonitoringEnabled When set to true enables bandwidth monitoring. Also requires the data
    set specified in the binaryFilePath attribute to support bandwidth
    monitoring. Defaults to True if not specified. (Optional)
    featureDetectionEnabled When set to true enables feature detection. Also requires the data set
    specified in the binaryFilePath attribute to support feature detection.
    Defaults to True if not specified. (Optional)
    -->

    <!-- IMPORTANT - Ensure this link is uncomment after purchasing Enhanced Device Data. -->
    <detection enabled="true" autoUpdate="true" binaryFilePath="~/App_Data/51Degrees.dat" />

    <!-- <imageOptimisation> elements controls the operation of the image optimiser. If not specified
    the functionality is disabled.

    enabled Controls whether image optimisation is enabled. Defaults to true. Device detection must
    also be enabled for image optimisation. (Optional)
    factor The request image dimensions of height and width are divided by this value and remainder
    subtracted from the requests height and width. The value can be used to limit the number
    of images that can be generated and stored in the cache. For example; a value of 50
    would result in images of width 50, 100, 150, 250, 300, etc pixels being generated.
    Optional default to 1.
    heightParam The name used when specifying the height of the image to return.
    Optional defaults to "h"
    maxHeight The maximum height in pixels the image optimiser is allowed to render. A value of 0
    indicates there is no maximum height. Optional defaults to 0.
    maxWidth The maximum width in pixels the image optimiser is allowed to render. A value of 0
    indicates there is no maximum width. Optional defaults to 0.
    widthParam The name used when specifying the width of the image to return.
    Optional defaults to "w"
    defaultAuto If an image is requested with a width or height set to "auto", the parameter will be
    changed to the value set in ‘defaultAuto’. This is most useful for clients without
    javascript that should still be served images, such as search crawlers.
    Optional, defaults to 50.
    -->
    <!-- <imageOptimisation enabled="true" maxWidth="1000" maxHeight="1000"
    widthParam="w" heightParam="h" factor="1" defaultAuto="50"/>
    -->
    </fiftyOne>
    </configuration>


    Kind Regards,
    Aleksandra Nitka
    0

    JoshGrew



    New Member


    Posts:27
    New Member


    --
    10 Apr 2019 03:36 PM
    Hi Aleksandra

    From looking at the source, some parts of the redirection module are executed as part of the Detection module. We can assume the request url that is being supplied to the method below is not a valid uri.

    private static void OnBeginRequest(object sender, EventArgs e)
    {
    if (sender is HttpApplication)
    {
    HttpContext context = ((HttpApplication)sender).Context;
    if (context != null)
    {
    context.Items[Constants.OriginalUrlKey] = context.Request.Url.ToString();
    }
    }
    0

    Lukasz Kalita



    New Member


    Posts:1
    New Member


    --
    15 Apr 2019 11:09 AM
    Hello,

    Thanks so much for reply
    Well still after some debugging session I can't really reproduce it...
    In logs I see :
    Request URL: http:///
    Request URL: http://'/styles/error
    Request URL: http://772'/

    But how it's event possible it's hitting such weird URLs.... Bundling ?
    I know it's a long shot but maybe You've heard about some situation or similar stories and have some idea how to force such exception ?

    Kind Regards,
    Aleksandra Nitka
    0

    JoshGrew



    New Member


    Posts:27
    New Member


    --
    17 Apr 2019 08:52 AM
    Hi Aleksandra

    I don't i'm afraid. We are limited in the support we can provide going forward as the issue appears to be with the request URL.
    0
    You are not authorized to post a reply.