Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC重新路由以接受密钥_C#_Asp.net_Asp.net Mvc 4_Routing_Asp.net Mvc Routing - Fatal编程技术网

C# MVC重新路由以接受密钥

C# MVC重新路由以接受密钥,c#,asp.net,asp.net-mvc-4,routing,asp.net-mvc-routing,C#,Asp.net,Asp.net Mvc 4,Routing,Asp.net Mvc Routing,在一个MVC项目中工作,我很难重新路由我的URL。 我现在拥有的是 然后运行索引操作并按照我的要求完成 我想能打字 然后像往常一样运行索引操作 我现在有 routes.MapRoute(null, "s/index/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }

在一个MVC项目中工作,我很难重新路由我的URL。 我现在拥有的是

然后运行索引操作并按照我的要求完成 我想能打字

然后像往常一样运行索引操作

我现在有

        routes.MapRoute(null, "s/index/{id}", new
        {
            controller = "Home",
            action = "Index",
            id = UrlParameter.Optional
        }
             );
但我有点被困在这里该怎么走。如蒙协助,将不胜感激。 谢谢

编辑:我的完整routeconfig课程

routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.IgnoreRoute(“sites/{*pathInfo}”)

在我的控制器中,actionresult索引为

    public ActionResult Index(string Key)
    {
        return Redirect(workflow.RetrieveURL(Key));
    }

因此,经过我们的所有评论,解决方案是:

routes.MapRoute(null, "s/{Key}",
new {
  controller = "Home",
  action = "Index",
  Key = UrlParameter.Optional
});

将此规则放在所有其他规则之前,优先考虑它

因此,在我们所有的评论之后,解决方案是:

routes.MapRoute(null, "s/{Key}",
new {
  controller = "Home",
  action = "Index",
  Key = UrlParameter.Optional
});

将此规则放在所有其他规则之前以给予优先权

您是否可以尝试模式
“s/{key}”
,同时将
id=UrlParameter.Optional
,更改为
key=UrlParameter.Optional
?@andercalil不幸的是,我仍然收到一个服务器错误,我还想补充一点,我希望s/MyOtherAction正常运行,但我只想在我使用abc123作为键运行索引操作时,您能提供错误详细信息吗?另外,如果有
Home/Index
action的签名也很好。您还有其他路由规则吗?@AndreCalil我已按要求添加了额外的代码。请看一看,让我知道你的想法。我一直收到404错误。”页面未找到“是的,您的模式应该是
“s/{key}”
,而不是
“s/index/{key}”
,您可以尝试一下模式
“s/{key}”
,同时将
id=UrlParameter.Optional
,改为
key=UrlParameter.Optional
?@AndreCalil不幸的是,我仍然遇到了一个服务器错误,我还想补充一点,我希望s/MyOtherAction正常运行,但我只想在转到以abc123为键运行索引操作时,您能提供错误详细信息吗?另外,如果有
Home/Index
action的签名也很好。您还有其他路由规则吗?@AndreCalil我已按要求添加了额外的代码。请看一看,让我知道你的想法。我一直收到404错误。”页面未找到“是,您的模式应该是
“s/{key}”
,而不是
“s/index/{key}”
@user2094139乐于帮助=)@user2094139乐于帮助=)