Is it possible to read a query in ASP.NET-MVC when / mysite is hit? Q = 123

I have a site that external sites link to with a campaign ID

http://www.example.com?cid=123

or (with a slash)

http://www.example.com/?cid=123

In case you skip the slash, most browsers will go off and add it for you. So, anyway, depending on what you type in the URL of my application, this is the second URL above. The QueryString parameter is always available.

I observed with ASP.NET MVC routing (perhaps even without) that when I use a virtual directory, I do not get the same behavior.

For example, if I have it 'http://www.example.com/virtualdirectory?cid=123', it will reach my " default.aspx" page (since it does not match any route). BUT, when I check the value Request.QueryString, it is empty. If I go to 'http://www.example.com/virtualdirectory?cid=123', then the value is QueryStringpresent in the object Request.

If I put a breakpoint in Default.aspx.csthe newly created MVC project (RTM version of MVC 1.0 - March 2009), then I will not see any query parameters.

I was wondering if there is a way to access these options in IIS6 and / or IIS7 if the user accesses the virtual directory using a URL, for example /virtualdirectory?cid=123.

There can be no solution, but I'm glad I noticed this before linking any partners to a virtual directory!

+3
5

. , http://www.example.com/virtualdirectory?cid=123 'vs' http://www.example.com/virtualdirectory/?cid=123 ' .

Visual Studio Development Server .

, , , Index HomeController.

, - /virtualdirectory? cid = 123 /virtualdirectory/default.aspx? , asp.net .

+1

--- , --- IIS 7 IIS 6, .

+1

http://www.example.com?cid=123

MVC. HomeController, Index() String cid. :

        public ActionResult Index(string cid)
    {

, , http://www.example.com, cid be null. , .

+1
0

http://www.example.com/123

Action, "Index" , Index

public ActionResult Index(int id){}

, AcceptVerbs,

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(int id){}

, , http://www.example.com/?cid=123&aid=456&bid=789, URL- .

0

Source: https://habr.com/ru/post/1705381/


All Articles