`
d2hellen
  • 浏览: 101798 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

在ASP.NET MVC 中获取当前URL、controller、action

阅读更多
一、 URL的获取很简单,ASP.NET通用:
【1】获取 完整url (协议名+域名+虚拟目录名+文件名+参数)
string url=Request.Url.ToString();
【2】获取 虚拟目录名+页面名+参数:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
【3】获取 虚拟目录名+页面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
【4】获取 域名:
string url=HttpContext.Current.Request.Url.Host;
【5】获取 参数:
string url= HttpContext.Current.Request.Url.Query;
【6】获取 端口:
Request.Url.Port


二、当前controller、action的获取
RouteData.Route.GetRouteData(this.HttpContext).Values["controller"]
RouteData.Route.GetRouteData(this.HttpContext).Values["action"]

RouteData.Values["controller"]
RouteData.Values["action"]
如果在视图中可以用
ViewContext.RouteData.Route.GetRouteData(this.Context).Values["controller"]
ViewContext.RouteData.Route.GetRouteData(this.Context).Values["action"]

ViewContext.RouteData.Values["controller"]
ViewContext.RouteData.Values["action"]
分享到:
评论

相关推荐

    ASP.NET实现MVC中获取当前URL、controller及action的方法

    主要介绍了ASP.NET实现MVC中获取当前URL、controller及action的方法,结合实例形式分析了asp.net mvc获取当前URL、controller及action的具体实现技巧,需要的朋友可以参考下

    ASP.NET MVC in Action

    《ASP.NET MVC in Action》详细讲解了ASP.NET MVC框架,并使用本书作者编写的开源项目http://codecampserver.com作为贯穿全书的示例。除了ASP.NET MVC框架本身,作者还介绍了Onion Architecture、领域驱动设计(DDD)...

    (5)asp.net mvc3控制器(Controller)以及Action

    (5)asp.net mvc3控制器(Controller)以及Action 时长一个小时左右

    [ASP.NET MVC 小牛之路] 文章系列

    九、[ASP.NET MVC 小牛之路]09 - Controller 和 Action (1) 十、[ASP.NET MVC 小牛之路]10 - Controller 和 Action (2) 十一、[ASP.NET MVC 小牛之路]11 - Filter 十二、[ASP.NET MVC 小牛之路]12 - Section、...

    ASP.NET MVC5 框架揭秘+源码打包下载

    相信精读本书的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的执行以及View的呈现等...

    《ASP.NET MVC 5框架揭秘》高清带书签

    相信精读《ASP.NET MVC 5 框架揭秘》的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的...

    ASP.NET MVC 3高级编程

    《asp.net mvc 3高级编程》 第1章 入门 1 1.1 asp.net mvc简介 1 1.1.1 asp.net mvc如何适应asp.net 1 1.1.2 mvc模式简介 2 1.1.3 mvc在web框架中的应用 2 1.1.4 asp.net mvc 3的发展历程 3 1.1.5 razor视图...

    ASP.NET MVC 5框架揭秘完整版 (蒋金楠) 高清pdf附源代码

    相信精读本书的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的执行以及View的呈现等...

    ASP.NET MVC 5 框架揭秘

    相信精读《ASP.NET MVC 5 框架揭秘》的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的...

    ASP.NET MVC 2 in action

    Microsoft ASP.NET MVC (model/view/controller) is a relatively new Web application framework that combines ASP.NET's power and ease of use with the stability and testability of a MVC framework....

    ASP.NET MVC 5 框架揭秘 108M

    相信精读《ASP.NET MVC 5 框架揭秘》的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的...

    ASP.NET MVC5 框架揭秘

    相信精读本书的读者一定能够将ASP.NET MVC从接收请求到响应回复的整个流程了然于胸,对包括路由、Controller的激活、Model元数据的解析、Action方法的选择与执行、参数的绑定与验证、过滤器的执行以及View的呈现等...

    Learning ASP.NET Core MVC Programming

    ASP.NET Core MVC helps you build robust web applications using the Model-View-Controller design. This guide will help you in building applications which can be deployed on non-windows platforms such ...

    模拟ASP.NET MVC是如何运行过程

    ASP.NET MVC的路由系统通过对HTTP请求的解析得到表示Controller、Action和其他相关的数据,并以此为依据激活Controller对象,调用相应的Action方法,并将方法返回的ActionResult写入HTTP回复中。为了更好的演示其...

    【ASP.NET编程知识】Asp.net实现MVC处理文件的上传下载功能实例教程.docx

    在 Asp.net Mvc 中,文件上传可以通过多种方式实现。第一种方式是使用 HTML 的 form 标签,设置 enctype 属性为 "multipart/form-data",然后使用 input 标签的 type 属性设置为 "file"。例如: <form action="/" ...

    Pro ASP.NET MVC 2 Framework, 2nd Edition

    In this book, the core model-view-controller (MVC) architectural concepts are not simply explained or discussed in isolation, but are demonstrated in action. You’ll work through an extended tutorial ...

    ASP.NET MVC Framework Unleashed(Stephen Walther)

    Walther explains the crucial concepts that make the Model-View-Controller (MVC) development paradigm work so well and shows exactly how to apply them with the ASP.NET MVC Framework. From controllers ...

Global site tag (gtag.js) - Google Analytics