00001: <%@ Application Language="VB" %>
00002: 
00003: <script RunAt="server">
00004: 
00005:     Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
00006:         '
00007:         'сначала инициализируем экземпляр маскировщика параметров
00008:         '
00009:         Application("ParmProtector8") = New VBNET2000.ParmProtector8
00010:         Dim PP8 As VBNET2000.ParmProtector8 = CType(Application("ParmProtector8"), VBNET2000.ParmProtector8)
00011:         CType(Application("ParmProtector8"), VBNET2000.ParmProtector8).RedirectUrl = "Error1.aspx"
00012:         CType(Application("ParmProtector8"), VBNET2000.ParmProtector8).ConfigKey = "CryptURLParm"
00013:         PP8.SaveKeyToSQL("SQLServer_ConnectionStrings") 'защита от рестарта
00014:         PP8.LoadKeyFromSQL("SQLServer_ConnectionStrings", PP8.DB_ID)
00015:         '
00016:         'здесь сгенерим ключи для быстрого симметричного шифрования куков капчи
00017:         '
00018:         Dim CryptInstance As New System.Security.Cryptography.DESCryptoServiceProvider
00019:         CryptInstance.GenerateKey()
00020:         CryptInstance.GenerateIV()
00021:         Application("DES_Key") = CryptInstance.Key
00022:         Application("DES_IV") = CryptInstance.Key
00023:         CryptInstance.Clear()
00024:         CryptInstance = Nothing
00025:         'для экономии ресурсов сохраним ссылки на готовые экземпляры классов шифрования
00026:         Application("DES_EnCrypt") = New VBNET2000.DES_EnCrypt(Application("DES_Key"), Application("DES_IV"))
00027:         Application("DES_DeCrypt") = New VBNET2000.DES_DeCrypt(Application("DES_Key"), Application("DES_IV"))
00028:         '
00029:         'теперь инициализируем неудаляемого админа
00030:         '
00031:         Try
00032:             Roles.CreateRole("UserAdmin")
00033:         Catch ex As Exception
00034:         Finally
00035:             Try
00036:                 Dim MainAdmin As MembershipUser = Membership.CreateUser(System.Configuration.ConfigurationManager.AppSettings("Admin_Login"), System.Configuration.ConfigurationManager.AppSettings("Admin_Pass"), System.Configuration.ConfigurationManager.AppSettings("Admin_Mail"))
00037:                 Roles.AddUserToRole(MainAdmin.UserName, "UserAdmin")
00038:                 Dim MyTypedProfile As ProfileCommon = ProfileBase.Create(MainAdmin.UserName)
00039:                 MyTypedProfile.usNik = "Администратор"
00040:                 MyTypedProfile.LoginIsActivate = True
00041:                 MyTypedProfile.Save()
00042:             Catch ex As Exception
00043:                 'все нормально просто этот юзер уже был создан в предыдущем перезапуске приложения               
00044:             End Try
00045:         End Try
..... 
00114:         '
00115:         'теперь инициализируем поток чистки неактивированных юзеров
00116:         '
00117:         Dim ClearJobThread As System.Threading.Thread = New System.Threading.Thread(AddressOf ClearJobSub)
00118:         ClearJobThread.Name = "ClearJobThread (Started " & Now.ToString & ")"
00119:         ClearJobThread.Start()
00120:         Application("ClearJobThread") = ClearJobThread
00121:         '
.....
00151:     End Sub
00152: 
00153:     Sub ClearJobSub()
00154:         Dim X As New VBNET2000.ClearInactiveUsers
00155:         While True
00156:             System.Threading.Thread.Sleep(System.Configuration.ConfigurationManager.AppSettings("ClearJobInterval") * 3600000)
00157:             'System.Threading.Thread.Sleep(System.Configuration.ConfigurationManager.AppSettings("ClearJobInterval") * 1000)
00158:             'диагностика фонового процесса
00159:             Dim ClearJobThread As System.Threading.Thread = CType(Application("ClearJobThread"), System.Threading.Thread)
00160:             My.Log.WriteEntry(ClearJobThread.Name & " : started at " & Now.ToString)
00161:             X.GO()
00162:         End While
00163:     End Sub
00164:     
00165:     Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
00166:         Dim ClearJobThread As System.Threading.Thread = CType(Application("ClearJobThread"), System.Threading.Thread)
00167:         ClearJobThread.Abort()
00168:     End Sub
00169:         
00170:     Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
00171:         AspErrorInfo.AspErrorInfo.ErrorRedirections()
00172:     End Sub
00173: 
......


Comments ( )
Link to this page: //www.vb-net.com/asp2/35/15.htm
< THANKS ME>