如何在asp.net mvc中创建用户友好的URL [英] how to create user friendly url's in asp.net mvc

查看:51
本文介绍了如何在asp.net mvc中创建用户友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建用户友好的网址asp.net mvc in c#


你好朋友我想做一个友好的网址我有一个网站,但我的网址看起来像 mydomain.com/Home /详情/ 195  我希望我的网址类似于  mydomain.com/Details/195/how-to-create-friendly-urls-in-asp -net



任何人请帮助我

解决方案

您可以使用映射来定义斜杠之间或之后的每个单词意味着什么。


http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC


在app_start中你会找到一个文件名RouteConfigs。


编辑它。


这是一个例子:

 public class RouteConfig {

public static void RegisterRoutes(RouteCollection routes){
routes.IgnoreRoute(" {resource}个.axd / {* PATHINFO}");

routes.MapRoute(null,
"",
new {
controller =" Product",action =" List",
category =(string)null,page = 1
}
);

routes.MapRoute(null,
" Page {page}",
new {controller =" Product",action =" List",category =( string)null},
new {page = @" \d +"}
);

routes.MapRoute(null,
" {category}",
new {controller =" Product",action =" List",page = 1}
);

routes.MapRoute(null,
" {category} / Page {page}",
new {controller =" Product",action =" List" },
new {page = @" \d +"}
);

routes.MapRoute(null," {controller} / {action}");
}
}


这是来自一本名为Pro asp.net MVC 5的书。

您可能需要考虑获取持有该书或类似书籍的副本。



由于这是一个asp.net mvc问题,你应该真的发布了在这里,为了更好的支持:


  http://forums.asp .net / 1146.aspx / 1?MVC



how to create user friendly url's in asp.net mvc in c#

Hello Friends i want to make a friendly url's i have a website but my url's look like mydomain.com/Home/Details/195 and i want my urls like mydomain.com/Details/195/how-to-create-friendly-urls-in-asp-net

Any one please help me 

解决方案

You can use mappings to define what each of the words between or after slashes means.

http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC

In app_start you will find a file name RouteConfigs.

Edit that.

Here's an example:

    public class RouteConfig {

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

            routes.MapRoute(null,
                "",
                new {
                    controller = "Product", action = "List",
                    category = (string)null, page = 1
                }
            );

            routes.MapRoute(null,
                "Page{page}",
                new { controller = "Product", action = "List", category = (string)null },
                new { page = @"\d+" }
            );

            routes.MapRoute(null,
                "{category}",
                new { controller = "Product", action = "List", page = 1 }
            );

            routes.MapRoute(null,
                "{category}/Page{page}",
                new { controller = "Product", action = "List" },
                new { page = @"\d+" }
            );

            routes.MapRoute(null, "{controller}/{action}");
        }
    }

That's from a book called Pro asp.net MVC 5.

You might want to consider getting hold of a copy of that or a similar book.

.

Since this is an asp.net mvc question you should really have posted here, for better support:

 http://forums.asp.net/1146.aspx/1?MVC


这篇关于如何在asp.net mvc中创建用户友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆