Declaring a global Request.ServerVariable variable
After many many years of using Classic ASP, I am attempting to delve into the world of ASP.Net using VB.
I have gotten way to use to being able to declare variables on a page, inlclude that file and use it everywhere.
I am struggling to declare a global variable. I just need
Then use it on a page as
Dim TheUser As String = Request.ServerVariables("AUTH_USER")
<%=TheUser%>
I have tried
But then I get "'Request' is not decla开发者_运维百科red."
Module GlobalVars
Dim TheUser As String = Request.ServerVariables("AUTH_USER")
End Module
If I use Dim TheUser As String = Request.ServerVariables("AUTH_USER")
within a Page_Load sub, the Request part is fine, but then I cant use it on my .aspx page. I get 'TheUser' is not declared. It may be inaccessible due to its protection level.
I apologize in advance as if this an extremely remedial question.
I just dont know where I am suppose to declare it, or maybe you can't declare variables to be used everywhere.
You want:
Module GlobalVars
Dim TheUser As String = Httpcontext.Current.Request.ServerVariables("AUTH_USER")
End Module
Welcome to .Net!
I would suggest that you abandon the Classic ASP way of doing things, and delve into more more web architecture and practices.
With that being said, look at Forms Authentication to start. You will have access to objects that will have the values you are looking to use globally.
Obviously there are many ways to do things, and this is just one.
精彩评论