Mvc icon indicating copy to clipboard operation
Mvc copied to clipboard

Dots in URL causes 404 with ASP.NET Core 1.0 MVC 6 and IIS 8.5

Open MatLeger opened this issue 10 years ago • 7 comments

After adding app.UseStaticFiles() to Startup.cs urls with dots in them cause a 404 error. In this example the page is trying to make an ajax call to get some data and there is a dot in the query string. iiserror

I found some SO articles for similar problems have tried changing the web.config by adding various handlers that are supposed to tell IIS to treat specific urls as MVC routes instead of static files but I still get the error. <add name="UrlRoutingHandler" path="/Grid/*" verb="GET" type="System.Web.Routing.UrlRoutingHandler,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>

Dots in URL causes 404 with ASP.NET mvc and IIS ASP.NET MVC Url Route supporting (dot)

There is no error when running debug from VS with weblistener. Is there a different way this is solved with ASP.NET Core 1.0 MVC 6 and IIS? I'm using DNX 1.0.0 RC 1.

MatLeger avatar Feb 11 '16 22:02 MatLeger

Can you share with us your code so that we can take a look?

danroth27 avatar Feb 12 '16 18:02 danroth27

@MatLeger Based on the request url, I suppose you are running the application in a virtual directory? If yes, there is a know issue with this kind of set up. Just wondering if you are hitting this issue.

I doubt if the dot . in the request is an issue here as its in the query string and not the path itself which static file middleware looks for. Are you sure your app works fine without adding this middleware?

Can you try with the following workaround related to running in a virtual directory? https://github.com/aspnet/Hosting/issues/416#issuecomment-149046552

For latest status on this issue, you can check https://github.com/aspnet/IISIntegration/issues/14

kichalla avatar Feb 16 '16 17:02 kichalla

I have tried to simplify the code so it's easier to share but in doing so I haven't been able to reproduce the original problem. I'm using the Kendo MVC Grid by Telerik and that is the control that is creating the request that is failing in IIS.

This is a snippet from the request header:

GET /Grid/ReadItems?sort=SubItems%5B3%5D.Value-asc&page=1&pageSize=30&group=&filter=&appGuid=d6366928-6ff0-4efa-9294-611c66dda85d 

This is the Controller action that should handle the Grid's requests:

[HttpGet]
public IActionResult ReadItems([DataSourceRequest] DataSourceRequest request, Guid? appGuid)
{
    IEnumerable<GridItem> items = GetItems(appGuid.Value);
    return Json(items.ToDataSourceResult(request));
}

If I create another action that doesn't use their DataSourceRequest object but instead has all of the parameters listed in the request and submit my own request via $.get() the request is successful.

I have opened a support ticket with Telerik and will investigate further with them.

MatLeger avatar Feb 16 '16 18:02 MatLeger

@kichalla Yes I'm running the application in a virtual directory. I had run into the virtual directory problem prior to this issue and had already implemented the work around you suggested in my web app. Everything is working fine in the app except this one request that is being created by the Kendo MVC Grid.

MatLeger avatar Feb 16 '16 18:02 MatLeger

If I create another action that doesn't use their DataSourceRequest object but instead has all of the parameters listed in the request and submit my own request via $.get() the request is successful.

Could you share how the type DataSourceRequest looks like?

kichalla avatar Feb 16 '16 18:02 kichalla

F12 shows the following metadata for DataSourceRequest:

namespace Kendo.Mvc.UI
{
    public class DataSourceRequest
    {
        public DataSourceRequest();

        public IList<AggregateDescriptor> Aggregates { get; set; }
        public IList<IFilterDescriptor> Filters { get; set; }
        public IList<GroupDescriptor> Groups { get; set; }
        public int Page { get; set; }
        public int PageSize { get; set; }
        public IList<SortDescriptor> Sorts { get; set; }
    }
}

namespace Kendo.Mvc
{
    public class AggregateDescriptor : IDescriptor
    {
        public AggregateDescriptor();

        public ICollection<AggregateFunction> Aggregates { get; }
        public string Member { get; set; }

        public void Deserialize(string source);
        public string Serialize();
    }
}

namespace Kendo.Mvc
{
    //
    // Summary:
    //     Represents a filtering abstraction that knows how to create predicate filtering
    //     expression.
    public interface IFilterDescriptor
    {
        //
        // Summary:
        //     Creates a predicate filter expression used for collection filtering.
        //
        // Parameters:
        //   instance:
        //     The instance expression, which will be used for filtering.
        //
        // Returns:
        //     A predicate filter expression.
        Expression CreateFilterExpression(Expression instance);
    }
}

namespace Kendo.Mvc
{
    //
    // Summary:
    //     Represents grouping criteria.
    public class GroupDescriptor : SortDescriptor
    {
        public GroupDescriptor();

        //
        // Summary:
        //     Gets or sets the aggregate functions used when grouping is executed.
        public AggregateFunctionCollection AggregateFunctions { get; }
        //
        // Summary:
        //     Gets or sets the content which will be used from UI.
        public object DisplayContent { get; set; }
        //
        // Summary:
        //     Gets or sets the type of the member that is used for grouping. Set this property
        //     if the member type cannot be resolved automatically. Such cases are: items with
        //     ICustomTypeDescriptor, XmlNode or DataRow.
        public Type MemberType { get; set; }

        //
        // Summary:
        //     Changes the Kendo.Mvc.SortDescriptor to the next logical value.
        public void CycleSortDirection();
        protected override void Serialize(IDictionary<string, object> json);
    }
}

namespace Kendo.Mvc
{
    //
    // Summary:
    //     Represents declarative sorting.
    public class SortDescriptor : JsonObject, IDescriptor
    {
        public SortDescriptor();
        public SortDescriptor(string member, ListSortDirection order);

        //
        // Summary:
        //     Gets or sets the member name which will be used for sorting.
        public string Member { get; set; }
        //
        // Summary:
        //     Gets or sets the sort direction for this sort descriptor. If the value is null
        //     no sorting will be applied.
        public ListSortDirection SortDirection { get; set; }

        public void Deserialize(string source);
        public string Serialize();
        protected override void Serialize(IDictionary<string, object> json);
    }
}

MatLeger avatar Feb 16 '16 18:02 MatLeger

@MatLeger Based on your investigation that the values bind properly when not using Telerik's object model and what I have tried myself, I am suspecting if the problem is with Telerik's binding of data. If yes, I would have expected a 400 Bad Request as that seems more appropriate instead of 404 here. I am going to close this issue now and feel free to reopen it if you have additional details.

kichalla avatar Feb 19 '16 18:02 kichalla