开发者

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

Dim TheUser As String = Request.ServerVariables("AUTH_USER")
Then use it on a page as <%=TheUser%> I have tried
    Module GlobalVars
         Dim TheUser As String = Request.ServerVariables("AUTH_USER")
    End Module
But then I get "'Request' is not decla开发者_运维百科red."

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜