7

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?

Community
  • 1
  • 1
Kemal Tezer Dilsiz
  • 3,739
  • 5
  • 24
  • 43
  • Why do you even need that ? Why not just put the action method name and controller name ? Won't that work ? – Shyju Aug 10 '16 at 14:12
  • Honestly I am not sure if it would work, I am fairly new to .NET Core. I assume that I could not do the same for this code though: `if (jQuery == undefined) loadjsfile("@Request.Url.GetLeftPart(UriPartial.Authority)/Scripts/jquery-1.11.2.min.js"); loadjsfile("@Request.Url.GetLeftPart(UriPartial.Authority)/Scripts/jquery.validate.min.js"); loadjsfile("@Request.Url.GetLeftPart(UriPartial.Authority)/Scripts/jquery.validate.unobtrusive.min.js"); loadjsfile("@Request.Url.GetLeftPart(UriPartial.Authority)/Scripts/contactusform.js");` – Kemal Tezer Dilsiz Aug 10 '16 at 14:21
  • I would be happy to read a link or research a particular concept which could explain about a particular replacement using tag helpers and such but like in my previous comment, I also have it in a function. Please let me know if there is an article/book that could be useful for this situation! – Kemal Tezer Dilsiz Aug 10 '16 at 14:31
  • I cannot give a complete answer to both the GetLeftPart and the Request in a Controller, but for the GetLeftPart, you can use GetComponents. See this answer: http://stackoverflow.com/a/27473521/154480 – Christian Rondeau Oct 26 '16 at 17:34

1 Answers1

6

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)
Peter Pompeii
  • 1,415
  • 1
  • 14
  • 16