Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# 根据请求值确定操作方法的名称_C#_Asp.net Mvc - Fatal编程技术网

C# 根据请求值确定操作方法的名称

C# 根据请求值确定操作方法的名称,c#,asp.net-mvc,C#,Asp.net Mvc,正如我在Asp.NETMVC中所理解的,对服务器的请求被映射到控制器和操作。例如,如果地址栏中有stackoverflow.com/questions/ask,则表示请求映射到问题控制器和ask操作方法 我的问题是,如果你在你的网站上有一个私人区域,你的网站的客户如何。你会如何使用这个范例来写呢?这意味着如果我在登录到个人区域时拥有堆栈溢出帐户,地址栏stack overflow.com/users中会显示一个数字和我的用户名。如何编写名称为用户用户名的操作?换句话说,如何编写没有名称的方法,其

正如我在Asp.NETMVC中所理解的,对服务器的请求被映射到控制器和操作。例如,如果地址栏中有stackoverflow.com/questions/ask,则表示请求映射到问题控制器和ask操作方法


我的问题是,如果你在你的网站上有一个私人区域,你的网站的客户如何。你会如何使用这个范例来写呢?这意味着如果我在登录到个人区域时拥有堆栈溢出帐户,地址栏stack overflow.com/users中会显示一个数字和我的用户名。如何编写名称为用户用户名的操作?换句话说,如何编写没有名称的方法,其名称将由用户确定

您可以设置路由的优先级:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "questionsRoute",
                url: "Questions/Ask/{id}",
                defaults: new { controller = "Question", action = "Ask", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Default",
                url: "users/{id}",
                defaults: new { controller = "User", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

您可以设置路由的优先级:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "questionsRoute",
                url: "Questions/Ask/{id}",
                defaults: new { controller = "Question", action = "Ask", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Default",
                url: "users/{id}",
                defaults: new { controller = "User", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

有几种方法可以做到这一点,例如路线参数。您尝试过什么吗?有几种方法可以做到这一点,例如路线参数。你试过什么吗?@J.Programmer代码没有经过测试。如果您有任何问题,请选择白色路线。现在让我来。我会改变it@J.Programmer代码没有经过测试。如果您有任何问题,请选择白色路线。现在让我来。我会换的