我有一个控制器,想要在其上定义默认路由,如下所示:
public class SignInController : Controller
{
[Route("", Name = "Default")]
public ActionResult Index()
{
return View();
}
}
<{1>}上的{p>我评论RoutingConfig
MapRoute
当我开始服务器时,我得到了:
HTTP错误403.14 - 禁止将Web服务器配置为不列出 这个目录的内容。
我做错了什么?
答案 0 :(得分:3)
您正在进行属性路由但缺少配置...
$ ./jboss-cli.sh --connect --controller=localhost:9999
org.jboss.as.cli.CliInitializationException: Failed to connect to the controller
at org.jboss.as.cli.impl.CliLauncher.initCommandContext(CliLauncher.java:284)
at org.jboss.as.cli.impl.CliLauncher.main(CliLauncher.java:262)
at org.jboss.as.cli.CommandLineMain.main(CommandLineMain.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.modules.Module.run(Module.java:292)
at org.jboss.modules.Main.main(Main.java:455)
Caused by: org.jboss.as.cli.CommandLineException: The controller is not available at localhost:9999
at org.jboss.as.cli.impl.CommandContextImpl.tryConnection(CommandContextImpl.java:969)
at org.jboss.as.cli.impl.CommandContextImpl.connectController(CommandContextImpl.java:808)
at org.jboss.as.cli.impl.CommandContextImpl.connectController(CommandContextImpl.java:784)
at org.jboss.as.cli.impl.CliLauncher.initCommandContext(CliLauncher.java:282)
... 8 more
Caused by: java.io.IOException: java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeForResult(AbstractModelControllerClient.java:129)
at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:71)
at org.jboss.as.cli.impl.CommandContextImpl.tryConnection(CommandContextImpl.java:947)
... 11 more
Caused by: java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
...将映射应用程序的属性定义路径。
此外,如果您要使用属性路由,您可能需要为控制器设置路由前缀。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
/*routes.MapRoute("Default", "{controller}/{action}/{id}",
new {controller = "SignIn", action = "Index", id = UrlParameter.Optional}
);*/
}
如果您希望[RoutePrefix("SignIn")]
public class SignInController : Controller
{
//eg: GET signin/
[Route("", Name = "Default")]
public ActionResult Index()
{
return View();
}
}
映射到您的根,请将SignInController.Index
设置为RoutePrefix
(空字符串)