In .NET is it possible to get the HttpContext of the current page from within an external class?
So, for example in my page test1.aspx codebehind I've got:
Dim blah As New FeedWriter()
blah.Run()
But inside FeedWriter.vb, can I get the HttpContext of test1.aspx? Or would I have to pass it in to Run()? (I'm unwilling to do the latter because FeedWriter implements an interface which will need to be re-written if it's to take arguments)
Aryan Kumar
06-Jul-2023Sure, I can help you with that. Here are the steps on how to get .NET HttpContext for isolated code block:
System.Web
namespace.HttpContext.Current
property.Here is an example of how to get .NET HttpContext for isolated code block:
VB.Net
Here is an explanation of the code:
HttpContext.Current
property returns the current HttpContext object.IPrincipal
interface represents a user's identity.Identity.Name
property of theIPrincipal
interface returns the user's name.Sumit Kesarwani
27-Aug-2014You can use the Current property of the HttpContext class:
HttpContext.Current;