How to get root URL when running in OWIN asp.net web api

I found many posts very similar to this, but I did not find anything that would work for me.

I have an asp.net Web Api2 application (not vnext) running under IIS and using the Owin startup class.

When setting the root url for this will be something like

http://localhost/appvirtualdirectory

where appvirtualdirectoryis the name of the virtual directory for which it is configured to work in IIS.

Is there a way at startup where I don't have the Request property, i.e. in the method Startup.Configureto get the root url including the virtual directory used?

+4
source share
2 answers

try it

HttpRuntime.AppDomainAppVirtualPath

This is true for running both globally and owin

https://msdn.microsoft.com/en-us/library/system.web.httpruntime(v=vs.110).aspx

0

:

//you have some options but i will show you the easiest
var request = HttpContext.Current.GetOwinContext().Request;
var path =  request.Scheme +
              Uri.SchemeDelimiter +
              request.Host +
              request.PathBase;

, .

https://msdn.microsoft.com/en-us/library/microsoft.owin.owinrequest(v=vs.113).aspx

-2

Source: https://habr.com/ru/post/1650874/


All Articles