我有以下由 Kentico 创建的用于预览页面的 url:
但它没有影响我的任何 Controller 或操作 - 在我的路由配置中,我有以下 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 命中预览 Controller ,或者至少捕获所有,但两个 Controller 都没有被命中,我只是得到一个 404 找不到资源。
奇怪的是,如果我从 url 中删除 /-/
或者在它旁边放一个字母或数字 /-1/
,那么预览 Controller 将被点击.有谁知道为什么 /-/
导致我的代码没有命中任何 Controller ?
这是我的预览 Controller :
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();
}
}
删除它允许我的路由启动并且 Controller 被击中
关于c# - 网址没有命中任何 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44822489/