asp mvc 404 когда + в URL - PullRequest
       22

asp mvc 404 когда + в URL

1 голос
/ 15 октября 2011

У меня проблема с asp mvc 3 .Когда я помещаю символ + в URL, я всегда получаю ошибку 404 .Все запросы AJAX получить запрос.

Если я сделаю этот запрос Тест / Подробности / + Я получу 404: Тест / Подробности / +

Это запрос в фиддлере: GET /Test%2FDetails%2F%2B?t=1318678807718 HTTP/1.1

Вот маршруты.

routes.MapRoute(
    "PagingTwoTest", // Route name
    "{controller}/{action}/{tag}/p{currentPage}/p{secCurrentPage}/{*term}", // URL with parameters
    new { secCurrentPage = UrlParameter.Optional, term = UrlParameter.Optional }, // Parameter defaults
    new { currentPage = "\\d+", secCurrentPage = "\\d+" }
);

routes.MapRoute(
    "PagingTwo", // Route name
    "{controller}/{action}/p{currentPage}/p{secCurrentPage}/{*term}", // URL with parameters
    new { secCurrentPage = UrlParameter.Optional, term = UrlParameter.Optional }, // Parameter defaults
    new { currentPage = "\\d+", secCurrentPage = "\\d+" }
);

routes.MapRoute(
    "Paging", // Route name
    "{controller}/{action}/p{currentPage}/{*term}", // URL with parameters
    new { term = UrlParameter.Optional }, // Parameter defaults
    new { currentPage = "\\d+" }
);

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "DefaultName", // Route name
    "{controller}/{action}/{*id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

1 Ответ

1 голос
/ 30 ноября 2011

В ваших ограничениях вы не учитываете, когда кто-то вводит строку, вы всегда запрашиваете цифру, поэтому я думаю, что вы можете попробовать:

routes.MapRoute(
    "TestDetails", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { 
        controller = "Test", 
        action = "Details", 
        id = UrlParameter.Optional 
    }
);

Так что в вашем TestController вы можете запросить строку:

public class TestController : Controller
{
    ....
    ....

    public ActionResult Details(string? id) //So you can verify if is null
    {
        ViewData["variable"] = id;
        return View();
    }
    ....
    ....
}

А в вашем Details.aspx вы можете положить что-то вроде этого:

<%@ Page Language="C#" 
    MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Title, what you want
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p> Blah, blah, blah, you request this: <%: ViewData["variable"] %> </p>
</asp:Content>
...