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
Post a Comment