The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.
So given your URL of:
http:
the
RawUrl
will be:
/ip-myserver/d$/Websites/mysites.net/pdfFiles/archive/Example.pdf
This will be resolved relative to the current path. So if your application is on drive
C:
, it will be looking for a file located in:
C:\ip-myserver\d$\Websites\mysites.net\pdfFiles\archive\Example.pdf
It looks like you're trying to load the file from a UNC path, which should be:
\\ip-myserver\d$\Websites\mysites.net\pdfFiles\archive\Example.pdf
Try something like this:
public void ProcessRequest(HttpContext context)
{
dynamic emp = context.Session["EmpID"];
if (emp == null || string.IsNullOrEmpty(emp))
{
HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.Flush();
return;
}
Uri path;
if (!Uri.TryCreate("file:/" + context.Request.RawUrl, UriKind.Absolute, out path))
{
HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.Flush();
return;
}
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment");
context.Response.TransmitFile(path.LocalPath);
context.Response.Flush();
context.Response.Clear();
context.ApplicationInstance.CompleteRequest();
}
NB: You'll need to make sure that your application pool is running as a user which has permission to read files from the UNC path. You'll probably need to avoid using the default admin shares (
d$
), and switch to using specific folder shares instead.