asp.net - Finding the request's physical path -


in asp.net 5, how retrieve physical path of request if i'm creating asp.net middleware?

public async task invoke(httpcontext context) {     var request = context.request 

previously have either leveraged:

httpserverutility.mappath()

or

system.web.request.physicalpath()

the new microsoft.aspnet.http.request object has path property, , i'm unclear how convert request path filesystem path.

you can use ihostingenvironment service follows:

public class physicalpathmiddleware {     private readonly requestdelegate _next;     private readonly ihostingenvironment _hostingenvironment;     public physicalpathmiddleware(requestdelegate next, ihostingenvironment hostingenvironment)     {         _next = next;         _hostingenvironment = hostingenvironment;     }     public async task invoke(httpcontext context)     {         var physicalfileinfo = _hostingenvironment.webrootfileprovider.getfileinfo(context.request.path);         var physicalfilepath = physicalfileinfo.physicalpath;     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -