Url 没有命中任何动作
Url not hitting any actions
我有以下 url 由 Kentico 创建以预览页面:
但它没有影响我的任何控制器或操作 - 在我的路线配置中,我有以下 2 条路线:
// Kentico CMS Console Preview Route
routes.MapRoute(
name: "Preview",
url: "cmsctx/pv/{username}/culture/{culture}/wg/{workflowGuid}/h/{hash}/{*pathname}",
defaults: new { controller = "Preview", action = "Index" });
// Default catch all route
routes.MapRoute(
name: "Default",
url: "{*pathname}",
defaults: new { controller = "Alias", action = "CatchAll" });
我希望上面的 url 能够击中预览控制器,或者至少是全部捕获,但是两个控制器都没有被击中,我只是得到一个 404 找不到资源。
奇怪的是,如果我从 url 中删除 /-/
或者在其旁边放置一个字母或数字 /-1/
,那么预览控制器将被点击。有谁知道为什么 /-/
导致我的代码无法访问任何控制器?
这是我的预览控制器:
public class PreviewController : Controller
{
public ActionResult Index(PreviewModel model)
{
model = previewModelBuilder.GetPreviewModel(model);
if (model.Page != null)
{
return View(model);
}
else
{
throw new HttpException(404, "Page not found");
}
}
}
好的,我发现这与 Kentico 所做的事情有关 - 在我的 Global.asax 中,我注册了以下内容:
ApplicationConfig.RegisterFeatures(ApplicationBuilder.Current);
这会运行以下内容:
public static void RegisterFeatures(ApplicationBuilder builder)
{
if (builder != null)
{
builder.UsePreview();
}
}
删除它允许我的路由启动并且控制器被击中
我有以下 url 由 Kentico 创建以预览页面:
但它没有影响我的任何控制器或操作 - 在我的路线配置中,我有以下 2 条路线:
// Kentico CMS Console Preview Route
routes.MapRoute(
name: "Preview",
url: "cmsctx/pv/{username}/culture/{culture}/wg/{workflowGuid}/h/{hash}/{*pathname}",
defaults: new { controller = "Preview", action = "Index" });
// Default catch all route
routes.MapRoute(
name: "Default",
url: "{*pathname}",
defaults: new { controller = "Alias", action = "CatchAll" });
我希望上面的 url 能够击中预览控制器,或者至少是全部捕获,但是两个控制器都没有被击中,我只是得到一个 404 找不到资源。
奇怪的是,如果我从 url 中删除 /-/
或者在其旁边放置一个字母或数字 /-1/
,那么预览控制器将被点击。有谁知道为什么 /-/
导致我的代码无法访问任何控制器?
这是我的预览控制器:
public class PreviewController : Controller
{
public ActionResult Index(PreviewModel model)
{
model = previewModelBuilder.GetPreviewModel(model);
if (model.Page != null)
{
return View(model);
}
else
{
throw new HttpException(404, "Page not found");
}
}
}
好的,我发现这与 Kentico 所做的事情有关 - 在我的 Global.asax 中,我注册了以下内容:
ApplicationConfig.RegisterFeatures(ApplicationBuilder.Current);
这会运行以下内容:
public static void RegisterFeatures(ApplicationBuilder builder)
{
if (builder != null)
{
builder.UsePreview();
}
}
删除它允许我的路由启动并且控制器被击中