使用ASP.NET Global.asax 文件
来源:互联网 发布:php架构师工资 编辑:程序博客网 时间:2024/05/21 08:40
这个例子只是很简单地使用了一些Global.asax 文件中的事件;重要的是要意识到这些事件是与整个应用程序相关的。这样,所有放在其中的方法都会通过应用程序的代码被提供,这就是它的名字为Global 的原因。
这里是前面的例子相应的 VB.NET 代码:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)Application("Title") = "Builder.com Sample"End SubSub Session_Start(ByVal sender As Object, ByVal e As EventArgs)Session("startValue") = 0End SubSub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)' Extract the forms authentication cookieDim cookieName As StringcookieName = FormsAuthentication.FormsCookieNameDim authCookie As HttpCookieauthCookie = Context.Request.Cookies(cookieName)If (authCookie Is Nothing) Then' There is no authentication cookie.ReturnEnd IfDim authTicket As FormsAuthenticationTicketauthTicket = NothingTryauthTicket = FormsAuthentication.Decrypt(authCookie.Value)Catch ex As Exception' Log exception details (omitted for simplicity)ReturnEnd TryDim roles(2) As Stringroles(0) = "One"roles(1) = "Two"Dim id As FormsIdentityid = New FormsIdentity(authTicket)Dim principal As GenericPrincipalprincipal = New GenericPrincipal(id, roles)' Attach the new principal object to the current HttpContext objectContext.User = principalEnd SubSub Application_Error(ByVal sender As Object, ByVal e As EventArgs)Response.Write("Error encountered.")End Sub
资源
Global.asax 文件是 ASP.NET 应用程序的中心点。它提供无数的事件来处理不同的应用程序级任务,比如用户身份验证、应用程序启动以及处理用户会话等。你应该熟悉这个可选文件,这样就可以构建出健壮的ASP.NET 应用程序。
- ASP.NET中使用Global.asax文件
- ASP.NET中使用Global.asax文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- ASP.NET中使用Global.asax文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- 使用ASP.NET Global.asax 文件
- asp.net Global.asax文件的使用
- 使用Asp.Net Global.asax 文件
- 【转载】Making Java Objects Comparable
- DOS批处理命令使用示例
- 创建 Web.config 文件
- 创建 Web.config 文件
- 给web.config文件加密
- 使用ASP.NET Global.asax 文件
- C语言学习
- windows下的svn配置
- xml的二进制数据传输和处理
- c#对xml操作 使用dateset编辑xml
- asp.net页面输出缓存
- 3 页面部分缓存
- ASP.Net性能优化——页面数据缓存
- 曾经从事软件开发的金融从业者