global-asax

global.asax scope and lifetime clarification

五迷三道 提交于 2019-12-13 13:53:20
问题 I need to implement several application-level behavior in a project I'm currently working on. There are several things I need to get my head around: 1. Where and how do I define application level variables? 2. What is the lifetime of these variables? or more accuratly, in what scenarios are they discarded? (Application pool recycle? App binaries dropped from memory and recompiled on the next request? etc.) 3. Is the global.asax file a good place to put a session counter, or maybe storing the

ASP.NET MVC PostAuthorizeRequest (and other events) not firing

允我心安 提交于 2019-12-13 13:07:29
问题 I'm working on the mvcForum project (on codeplex) and want to remove as much code as possible from the global.asax file - mostly to make it easier to integrate mvcForum into existing ASP.NET MVC application without changing too much code. I need to hook into the application events to be able to set the correct CultureInfo (depending on the users' choice etc) and other things. This isn't a problem with this in the global.asax file: protected void Application_PostAuthorizeRequest() { // Some

301 Redirect dynamic urls from database in asp.net

☆樱花仙子☆ 提交于 2019-12-13 05:44:36
问题 I have thousands of links which need to be redirect to new URL using 301 Permanent Redirect . I have all these urls in the Database table. I would like to know where should be these URLs should be loaded (only once). And can be used for 301 permanent redirect. Sample URLs: *RequestForURL* *301Redirect* why-me/onboard-experience/food-and-drink-for-all-tastes/family-casual/-> /why-me/family-test/ why-me/onboard-experience/food-and-drink-for-all-tastes/room-service/-> /why-me/onboard-experience

Get currently online users?

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:49:28
问题 After googling a bit I have found some tips about how to get online Users with ASP.NET. But I am using my own class for membership. The information I have found is: Log the users sessionId to database when the user logs in Log them out when their session time out What is your advice about this? 回答1: I have found this great article Hope helps someone 回答2: We use this approach at work so that when users upload data in separate but concurrent session to a webservice, we can catch 90% of the

How to start aspnet_wp.exe without firing Application_Start event

穿精又带淫゛_ 提交于 2019-12-12 23:04:24
问题 I'm trying to debug a web service (Windows XP SP3, VS 2008, ASP.NET 2, VB.NET). For most of it, if the asp.net worker process is already loaded, I can start the Windows form that calls the web service, attach to aspnet_wp.exe in Visual Studio, and then debug to my heart's content, but catching the Application Start event in global.asax is a pain. If I reset IIS, of course there is no process to attach to, until the Application start event is all over. The only way I've found to do this is

Help debugging - when does the Application_Start run in global.asax file?

混江龙づ霸主 提交于 2019-12-12 09:48:49
问题 Here's the snippet from my Global.asax: <script runat="server"> void Application_Start(object sender, EventArgs e) { // log this call EventLogger.Log("ApplicationStart"); } void Application_BeginRequest(object sender, EventArgs e) { // log what the user is doing UsageLogger.Log(UsageLogger.GetServerVariables()); } </script> When I open the log, I see many ApplicationStart calls interspersed with usage calls. Why does my application seem to restart so much? 回答1: Application_Start fires once

Session State Not Available In This Context - In Global.asax

你说的曾经没有我的故事 提交于 2019-12-12 08:25:02
问题 I am getting a 'session state not available in this context' error. The error is nested in the sender parameter of a number of methods within the Global.asax file: Application_BeginRequest Application_AuthenticateRequest Session_Start Application_Error The error happens on the very first page load (and all page loads thereafter). I've added a completely new and empty page, WebForm1.aspx, to the project and made it my start page. You'd think nothing could go wrong on an empty page . No code of

Global.asax - Application_Error - How can I get Page data?

走远了吗. 提交于 2019-12-12 07:30:07
问题 I have this code: using System.Configuration; void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError().GetBaseException(); string ErrorMessage = ex.Message; string StackTrace = ex.StackTrace; string ExceptionType = ex.GetType().FullName; string UserId = Getloggedinuser(); string WebErrorSendEmail = ConfigurationManager.AppSettings["WebErrorSendEmail"]; // save the exception in DB LogStuffInDbAndSendEmailFromDb(); } This is (most of) my code. In a small

Return the Method Name and Line Number upon Error in page in global.asax file

◇◆丶佛笑我妖孽 提交于 2019-12-12 03:00:35
问题 My code is as below , would like to get Page Name , Method Name and Page Line Number where error occured. void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs if (HttpContext.Current.Server.GetLastError() != null) { Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException(); string urlPath = Request.Url.ToString(); string errorMsg = ex.Message; // Need help on below ..... string pageName = ?????? string pageMethodName = ??????

asp.net c# app routing

孤人 提交于 2019-12-12 02:08:48
问题 I've been trying to get some routing up and running. I basically want this url: www.example.com/SomebodysName or www.example.com/agents/somebodysname ..to go to... www.example.com/portfolio.aspx?ran=somebodysname I have tried to use an example from MSDN, using globax.asax like this: void Application_Start(object sender, EventArgs e) { RegisterRoutes(System.Web.Routing.RouteTable.Routes); } public static void RegisterRoutes(System.Web.Routing.RouteCollection routes) { routes.MapPageRoute("",