ASP.NET属性路由在本地工作,但在实时服务器上部署时失败

时间:2019-04-07 09:22:16

标签: c# asp.net-mvc routing attributes asp.net-mvc-routing

我正在使用aspnet mvc属性路由,在本地一切正常,但是一旦将其部署在服务器上就会失败。我的路线配置看起来像这样

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            name: "Error",
            url:"error/{action}/{id}",
            defaults: new { controller = "Home", action = "Index" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );           
    }
}

我在索引视图中有一个url操作,可重定向到控制器中正确的路由/操作

<a href="@Url.HttpRouteUrl("zoro", new { adID = myAdID, Desc = urlDesc })" style="width:100%; height:250px; display:block; cursor:pointer;">

然后在我的控制器中,我有这个

[Route("ViewSingleAdID", Name = "zoro")]
public ActionResult ViewSingleAdID(int adID, string Desc)
    {
        // set some variables
        return RedirectToAction("ViewSingleAd", new { Desc = Desc });
    }

[Route("ViewAd/{Desc}")]
public ActionResult ViewSingleAd(string Desc)
{
    // code which returns view
    return View();
}

这在本地完美运行,但是为什么在服务器上的已部署版本上失败?

0 个答案:

没有答案