阅读本文后:.NET MVC-4 routing with custom slugs
我能够将解决方案应用到我的项目中:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).RouteHandler = new SlugRouteHandler(); ;
并对SlugRouteHandler
类进行了一些更改:
public class SlugRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var url = requestContext.HttpContext.Request.Path.TrimStart('/');
if (!string.IsNullOrEmpty(url))
{
if (url.Contains("_escaped_fragment_"))
requestContext.HttpContext.Response.StatusCode = 401;
else
requestContext.HttpContext.Response.StatusCode = 404;
FillRequest("Error","Index", requestContext);
}
return base.GetHttpHandler(requestContext);
}
private static void FillRequest(string controller, string action, RequestContext requestContext)
{
if (requestContext == null)
{
throw new ArgumentNullException("requestContext");
}
requestContext.RouteData.Values["controller"] = controller;
requestContext.RouteData.Values["action"] = action;
}
}
这是我当地主持人的结果,完美:
但是在将项目发布到主机后,它并没有像我预期的那样工作:
这是否有可能是因为服务器的配置?