In my .cshtml
page, we are calling an .aspx
page through virtual path (eg. /includes/header.aspx
) and trying to convert its output into a string and embed on the page.
But it’s throwing this error:
HttpException: The file ‘/includes/header.aspx’ does not exist
I tried executing the output of the .aspx
page, converting its output into string and embedding into cshtml page using HttpContext.Current.Server.Execute
as shown below.
using(new Tracer(virtualPath, httpContext.Request, httpContext.Request.Url))
{
using(StringWriter stringWriter = new StringWriter())
{
HttpContext.Current.Server.Execute(virtualPath, stringWriter);
var stringBuilder = stringWriter.GetStringBuilder();
razorOutput = stringWriter.ToString();
}
}
2