How can I get the raw URL for these files? You can just type the name of the file at the end of the path. Get the URL for your text file and replace the filename/path with the path to your datafile. Cyverse might be a little easier since you should be able to upload a single directory of your hub data (including hub.
The HttpRequest class is present in the System. Web namespace. During a web request, the HttpRequest class enables ASP.NET to read the HTTP values sent by a client. The method of this class is used to get the path information and save requests on the disk.
IHttpContextAccessor. HttpContext may be null if accessed outside of the request flow. To access information from HttpContext outside the request flow, copy the information inside the request flow.
This interface allows us to access the HttpContext property which in turn provides access to Request collection and also the Response property. You will need to add the AddHttpContextAccessor function in the ConfigureServices method of Startup class as shown below. You will need to import the following namespace.
It looks like you can't access it directly, but you can build it using the framework:
Microsoft.AspNetCore.Http.Extensions.UriHelper.GetFullUrl(Request)
You can also use the above as an extension method.
This returns a string
rather than a Uri
, but it should serve the purpose! (This also seems to serve the role of the UriBuilder
, too.)
Thanks to @mswietlicki for pointing out that it's just been refactored rather than missing! And also to @C-F to point out the namespace change in my answer!
Add the Nuget package / using:
using Microsoft.AspNetCore.Http.Extensions;
(In ASP.NET Core RC1 this was in Microsoft.AspNet.Http.Extensions)
then you can get the full http request url by executing:
var url = httpContext.Request.GetEncodedUrl();
or
var url = httpContext.Request.GetDisplayUrl();
depending on the purposes.
If you really want the actual, raw URL, you could use the following extension method:
public static class HttpRequestExtensions
{
public static Uri GetRawUrl(this HttpRequest request)
{
var httpContext = request.HttpContext;
var requestFeature = httpContext.Features.Get<IHttpRequestFeature>();
return new Uri(requestFeature.RawTarget);
}
}
This method utilizes the RawTarget
of the request, which isn't surfaced on the HttpRequest
object itself. This property was added in the 1.0.0 release of ASP.NET Core. Make sure you're running that or a newer version.
NOTE! This property exposes the raw URL, so it hasn't been decoded, as noted by the documentation:
This property is not used internally for routing or authorization decisions. It has not been UrlDecoded and care should be taken in its use.
In .NET Core razor:
@using Microsoft.AspNetCore.Http.Extensions
@Context.Request.GetEncodedUrl() //Use for any purpose (encoded for safe automation)
You can also use instead of the second line:
@Context.Request.GetDisplayUrl() //Use to display the URL only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With