Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace Request.Url.GetLeftPart(UriPartial.Authority) for .NET Core View class?

I am trying to migrate few View classes into .NET Core from .NET and I am having an issue with the lack of "Request" class methods. The following question might be related to my situation but I wasn't sure how to use UriBuilder or any of the other answer for this purpose. I wanted to ask something more specific and a little different.

What is the ASP.NET Core MVC equivalent to Request.RequestURI?

My specific code is as follows:

<form id="contactUs" method="post" action="@Request.Url.GetLeftPart(UriPartial.Authority)@Url.Action("ContactUsFormSubmit")" accept-charset="utf-8">

Specifically I need to replace the Request.Url.GetLeftPart(UriPartial.Authority) part of the code as I believe that it is not an available package for .NET Core.

Is there a replacement for .NET Core to get the "Authority" part of the Url? Could I be missing a simple reference etc due to my lack of experience in .NET/.NET Core?

like image 330
Kemal Tezer Dilsiz Avatar asked Aug 10 '16 13:08

Kemal Tezer Dilsiz


1 Answers

You can use the GetComponents method of the Uri class. This should work for your case:

Request.Url.GetComponents(UriComponents.Scheme | UriComponents.StrongAuthority, UriFormat.Unescaped)
like image 148
Peter Pompeii Avatar answered Sep 18 '22 20:09

Peter Pompeii