Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get URL in HTML / cshtml

Tags:

html

url

razor

I want to get the current URL into a string that I can use for e.g. share functionality later.

String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;

I get the error:

The name HttpContext does not exist in the current context.

Is there another way?

like image 836
Mr.Anderson Avatar asked May 25 '16 12:05

Mr.Anderson


1 Answers

In case you are using MVC 3 or higher: Here is a related questions.

In case you are using ASP .Net MVC Core 1.0 you should use this code:

Context.Request.Path
like image 88
Hello It's me Avatar answered Sep 26 '22 17:09

Hello It's me