I need to be able to get at the full URL of the page I am on from a user control. Is it just a matter of concatenating a bunch of Request variables together? If so which ones? Or is there a more simpiler way?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
if you need the full URL as everything from the http to the querystring you will need to concatenate the following variables
For
ASP.NET Core
you'll need to spell it out:Or you can add a using statement to your view:
then
The
_ViewImports.cshtml
might be a better place for that@using
Request.RawUrl
This property does everything you need, all in one succinct call.
I usually use
Request.Url.ToString()
to get the full url (including querystring), no concatenation required.Better to use
Request.Url.OriginalString
thanRequest.Url.ToString()
(according to MSDN)