Url在Asp.net MVC中欺骗 [英] Url tricks in Asp.net MVC

查看:91
本文介绍了Url在Asp.net MVC中欺骗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



朋友们,我是MVC新手,

i发现

http://demo.nopcommerce.com/25-virtual-gift-card [ ^ ]



http://demo.nopcommerce.com/customer-service-client-service [ ^ ]



http://demo.nopcommerce.com/electronics [ ^ ]



,我很困惑他们如何在没有{controller} / {的情况下创建网址动作}?



如何在Global.asax中创建和使用多个/各种路线。



in asp.net web项目我们在用户登录后使用session来存储用户id,在MVC中如何做到这一点。



请写或给一些参考,以便我加强我的知识。



提前感谢

Hi
friends ,I am very new in MVC,
i Found
http://demo.nopcommerce.com/25-virtual-gift-card[^]

http://demo.nopcommerce.com/customer-service-client-service[^]

http://demo.nopcommerce.com/electronics[^]

in nop commerce demo site,and I am confused how they create a url without {controller}/{action}?

How to create and use multiple/various Route in Global.asax.

in asp.net web project we use session for storing user id after user login,in MVC how to do that.

please write or give some reference so that i an enhance my knowledge.

thanks in advance

推荐答案

在MVC中,您可以添加自定义路由,例如,如果我有一个控制器和ActionResult类似如下

In MVC you can add custom route for example if i have an Controller and ActionResult like below
public class HelloController : Controller
  {
      //
      // GET: /Hello/

      public ActionResult Index()
      {
          return View();
      }





如果要将路径显示为 http:// localhost:56007 / 25-虚拟礼品卡 [ ^ ]每当你浏览http:// localhost:56007 / hello / index你应该添加如下的自定义路由



If you want to display the routes as http://localhost:56007/25-virtual-gift-card[^] whenever you browse http://localhost:56007/hello/index You should add custom route like below

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "SecondRoute",
                "25-virtual-gift-card",
                new { controller = "Hello", action = "Index" }
                );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Hello", action = "Index", id = UrlParameter.Optional }
            );
        }





有关 http://www.asp.net/mvc/tutorials/controllers-and-routing/creating-custom-routes-cs [< a href =http://www.asp.net/mvc/tutorials/controllers-and-routing/creating-custom-routes-cstarget =_ blanktitle =New Window> ^ ]

希望这有助于



For more custom routes about http://www.asp.net/mvc/tutorials/controllers-and-routing/creating-custom-routes-cs[^]
Hope this helps


这篇关于Url在Asp.net MVC中欺骗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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