


Detailed explanation of the ASP.NET method of obtaining controller, URL and action in MVC
This article mainly introduces the method of obtaining the current URL, controller and action in ASP.NET MVC. It analyzes the specific implementation skills of asp.net MVC to obtain the current URL, controller and action in the form of examples. Friends who need it can Refer to the following
The example of this article describes the method of obtaining the current URL, controller and action in ASP.NET implementation of MVC. Share it with everyone for your reference, the details are as follows:
Obtaining the URL is very simple, common for ASP.NET:
[1] Get the complete url
(Protocol name + domain name + virtual directory name + file name + parameters)
string url=Request.Url.ToString();
【2】Get the virtual directory name + page name + parameters:
string url=Request.RawUrl;
or
string url=Request.Url.PathAndQuery;
【3】Get the
virtual directory name + page name:
string url=HttpContext.Current.Request.Url.AbsolutePath;
or:
string url= HttpContext.Current.Request.Path;
【4】Get the domain name:
string url=HttpContext.Current.Request.Url.Host;
【5】 Obtain parameters:
string url= HttpContext.Current.Request.Url.Query;
[6] Obtain port:
Request.Url.Port
2. Obtain current controller and action
RouteData.Route.GetRouteData(this.HttpContext).Values["controller"] RouteData.Route.GetRouteData(this.HttpContext).Values["action"]
or:
RouteData.Values["controller"] RouteData.Values["action"]
If you can use it in view:
ViewContext.RouteData.Route.GetRouteData(this.Context).Values["controller"] ViewContext.RouteData.Route.GetRouteData(this.Context).Values["action"]
or:
ViewContext.RouteData.Values["controller"] ViewContext.RouteData.Values["action"]
[Related recommendations]
2. ASP Tutorial
3. Li Yanhui ASP Basic Video Tutorial
The above is the detailed content of Detailed explanation of the ASP.NET method of obtaining controller, URL and action in MVC. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

PHP function introduction—get_headers(): Overview of obtaining the response header information of the URL: In PHP development, we often need to obtain the response header information of the web page or remote resource. The PHP function get_headers() can easily obtain the response header information of the target URL and return it in the form of an array. This article will introduce the usage of get_headers() function and provide some related code examples. Usage of get_headers() function: get_header

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

When a SpringBoot novice creates a project, the Controller cannot be scanned for a series of problems 1.2.3.4.5.6. Another way is to add @ComponentScan(basePackages={"xxx.xxx.xx","xxx.xxx" when starting the service class) .xx”}) is the fully qualified name of the package, which can be used for multiple SpringBoot custom controllers. The SpringBoot custom controller route cannot be scanned and cannot be found because the startup class and the custom Controller package are not in the same directory. Officially recommended placement of application.java

Nowadays, many Windows users who love games have entered the Steam client and can search, download and play any good games. However, many users' profiles may have the exact same name, making it difficult to find a profile or even link a Steam profile to other third-party accounts or join Steam forums to share content. The profile is assigned a unique 17-digit id, which remains the same and cannot be changed by the user at any time, whereas the username or custom URL can. Regardless, some users don't know their Steamid, and it's important to know this. If you don't know how to find your account's Steamid, don't panic. In this article

DJI has not confirmed any plans to introduce a new action camera yet. Instead, it seems that GoPro will get ahead of its rival this year, having teased that it will introduce two new action cameras on September 4. For context, these are expected to a

Use url to encode and decode the class java.net.URLDecoder.decode(url, decoding format) decoder.decoding method for encoding and decoding. Convert into an ordinary string, URLEncoder.decode(url, encoding format) turns the ordinary string into a string in the specified format packagecom.zixue.springbootmybatis.test;importjava.io.UnsupportedEncodingException;importjava.net.URLDecoder;importjava.net. URLEncoder

Introduction In today's rapidly evolving digital world, it is crucial to build robust, flexible and maintainable WEB applications. The PHPmvc architecture provides an ideal solution to achieve this goal. MVC (Model-View-Controller) is a widely used design pattern that separates various aspects of an application into independent components. The foundation of MVC architecture The core principle of MVC architecture is separation of concerns: Model: encapsulates the data and business logic of the application. View: Responsible for presenting data and handling user interaction. Controller: Coordinates the interaction between models and views, manages user requests and business logic. PHPMVC Architecture The phpMVC architecture follows the traditional MVC pattern, but also introduces language-specific features. The following is PHPMVC
