global-asax

Can I programmatically determine the database “context” to use based on user credentials?

北战南征 提交于 2019-12-11 21:18:51
问题 This is a followup to the question here, where the answer seems to refer to an overly-complicated and overly-specific (EF, which I'm not using - not even using an ORM). There has to be a more straightforward way around this common scenario than the smoke, mirrors, and sorcery hinted at in that answer. Note: I encased "context" in parenthesis because I'm not using EF, so it is not a literal "dbcontext" that I'm talking about here. So I got to wondering: Could I set a global variable for each

How to inject dependencies per http request (or per http context) with unity 2.0 and asp.net mvc

匆匆过客 提交于 2019-12-11 13:04:57
问题 I've read a lot of info on this, but I can't find anything current (as of 1/2011) as to how exactly this should be done nowadays. I've read a couple of good posts that seem to have the answer, without the details. Older pre-unity-2 approaches mostly created custom lifetime managers. It appears the best way to do it now is to use a child container that is created at the beginning of the request and disposed at the end of the request, using container-managed lifetime. Another person said they

How “Session_Start” in Global.Asax works ?. MVC

一笑奈何 提交于 2019-12-11 11:40:27
问题 I'am trying uderstand how "Session_Start" in Global.Asax works. Let's say I've got few pages on my website. For example: I'am entering on "Page A", then function "Session_Start" is firing. Then I'am going to "Page B", and what than ?. Function will firing again, or not ?. I'am trying to write code which will check that cookie "User" exist, and if exist, code will return Session["userName"] variable, but I'am not sure is "Session_Start" good place for that.. 回答1: If you want to make session

Global.asax not firing on precompiled Sitefinity project

烂漫一生 提交于 2019-12-11 07:39:44
问题 I'm trying to launch a Sitefinity 4.2 project. As part of the project I need to register some controls within the global.asax file, like so: protected void Application_Start(object sender, EventArgs e) { //log call logStartUpCall(string.Concat("Application started at: ", DateTime.Now)); Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized); //log call logStartUpCall(string.Concat("Call made to

Custom 404 errors using Global.asax file not always working

半城伤御伤魂 提交于 2019-12-11 06:57:03
问题 We currently use the config file to throw the 404 error page, however we would like to move this to the Global.asax file as we want to be able to use multiple 404 error pages, depending on where the user is on the page. Our current setup: <customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> </customErrors> <httpErrors existingResponse="Replace" defaultResponseMode="Redirect" errorMode="Custom"> <remove statusCode="404"/> <error statusCode="404" responseMode="Redirect" path="

Castle Windsor PerWebRequest LifeStyle and Application_EndRequest

风格不统一 提交于 2019-12-11 06:24:51
问题 I'm registering some components related to Linq2Sql using PerWebRequest lifestyle. I see them get created, but they get destroyed before my global's Application_EndRequest method gets called. Is that by design? Does anyone know a work around? I want to call commit on my UnitOfWork object to submitchanges() at the end of every request. In addition to using the Global.asax Application_EndResult, I've also tried an IHttpModule with the same results. I'm using Castle 2.0. Here's how I'm

ASP.NET Capture and replace output in Global.asax

拟墨画扇 提交于 2019-12-11 01:48:26
问题 I need to replace some data that's sent from every page on my site, and I think doing it with Global.asax. This is what I have tried with so far: void Application_PreSendRequestContent(object sender, EventArgs e) { System.IO.StreamReader sr = new System.IO.StreamReader(Response.OutputStream); String output = sr.ReadToEnd(); Response.ClearContent(); Response.Write("Testing.."); } But this gives me an ArgumentException. What am I doing wrong? Is there any better way to do this? Thanks 回答1: Is

Raise Session_OnStart event from custom ASP.NET SessionStateProvider class

谁说我不能喝 提交于 2019-12-10 22:18:47
问题 I'm working on an asp.net project that uses an in-house developed custom SessionStateProvider class. Evidently, the Session_OnStart event is not firing. I have code in Global.asax to handle the event. I can only get this code to execute by changing the Web.config to use the default SessionStateProvider. What must I do to make my Session_OnStart code execute when I'm using a custom SessionStateProvider class? I have access to the source code. Update : It clearly says on MSDN that ordinarily,

ASP.NET MVC Error Logging in Both Global.asax and Error.aspx

巧了我就是萌 提交于 2019-12-10 21:59:40
问题 I'm creating an ASP.NET MVC application. I need to handle exceptions in two places. Global.asax.vb file: Public Class MvcApplication Inherits System.Web.HttpApplication ... Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) LogException(HttpContext.Current.Server.GetLastError(), Request) End Sub Shared Sub LogException(ByVal ex As Exception, ByRef r As System.Web.HttpRequest) ... End Sub End Class Views\Shared\Error.aspx file: <%@ Page Language="VB" Inherits="System.Web.Mvc

ASP.Net Session_Start always firing

ぃ、小莉子 提交于 2019-12-10 15:25:39
问题 I am a bit confused about the following: I set up an asp.net Website with some logic in the Session_Start() of the Global.asx. I expected that this even will only trigger once during a session. However the event fired with every single request. When I declare a dummy session object this fixed the problem. Also I can fix this problem when I add <sessionState mode="InProc" /> in the web.config. I use IIS7 and I checked the default value and this is already set to "In Process". I am missing