Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

asp.net mvc - Get full request url, including parameters in controller

How do I get the complete request URL (including query string) in my controller? Is it a matter of concatenating my URL and form parameters or is there a better way.

I checked this question, but it seems not to be applicable to MVC.

Correct me if I'm wrong.

Some more detailed information:

My call to my SearchController.AdvancedSearch() originates from a form with about 15 optional parameters. Because of the number of parameters and no possible way (I think) to have optional parameters passed in a clean way, I went for a catchall string that is handled in the controller.

Now I want my controller to store its call in a breadcrumb component so that when the crumb is clicked the exact same result can be fetched (with all, but not more, of the arguments included). To do this I need the entire request.URL, including the querystring.

In Request.RawURL, request.URL etc this query string is not included. In fact currently I do a plain function.

String.Format("{0}/{1}", request.Url, request.form)

This gives me some weird results (like submit button values etc), but it works. If there are suggestions on how to make this less of an ugly hack, please do tell.

I know where to find the current request, but I can't seem to find a raw URL anywhere though. They are all deprived from the querystring and I need that bit too.

My controller updates a collection of URLs in my BreadCrumb component. Therefore it needs the request URL. How do you suggest I take on this problem?

question from:https://stackoverflow.com/questions/261345/get-full-request-url-including-parameters-in-controller

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use Request.Url.PathAndQuery.

MVC5: use Request.RequestUri.PathAndQuery


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...