MVC :: Initialize Method Called Multiple Times?

Jul 6, 2010

I'm overriding the Controller.Initialize method to set some stuff before each ActionResult is executed, however I'm finding that the method is being called multiple times for each request (anywhere between 2 - 10 times). I'm running in Cassini.

My hunch is that it is running for all static files (images, css etc) as well as the requested action - although I may be wrong? I thought maybe something was wrong in my web.config but it all looks right to me.

View 6 Replies


Similar Messages:

SelectMethod In ObjectDatasource Getting Called Multiple Times With Multiple Datapagerfield?

Oct 7, 2010

so here is the setup. I am building a page that has a listview, a datapager, and 3 datapagerfield (2 x NextPreviousPagerField, 1 x NumericPagerField), and a objectdatasource to tide all of this together.

It was all working fine until I put a breakpoint into the SelectMethod specified in the objectdatsource control. It seems like that for each datapagerfield control, it is calling the selectmethod and selectcount method. Hence, whenever a user paged, it calls the database 6 times instead of 2 (I don't have caching turned on atm). If I remove one datapagerfield, it will remove 2 calls.

Now this is build in asp.net 3.5 SP1 in VS2008. When I copied the same code files to a asp.net 4.0 VS2010 solution, it duplicate call seems to be gone.

Is this a bug in asp.net 3.5 SP1?

View 1 Replies

How Many Times Does HttpModule Init() Method Get Called During Application's Life

Jul 30, 2010

Web application initialization is as follows:

As we know when IIS receives the first request for a particular Asp.net application resource, IIS creates an instance of a HttpApplication (defined in global.asax codebehind).When this new instance is created it's initialization happens that also checks all configured HTTP modules.All modules are then instantiated and put in the application's Modules collection (of type HttpModuleCollection)modules are looped through and their Init() method is called (when they register for request events)

As far as I understand it the above scenario happens when a web application is started/initialized (hence application start event).What happens with modules?

Are they (re)instatiated on each request or reused from the Modules property on each consecutive request while the web application is alive? As I understand IIS and Asp.net they are reused through the whole life of a web application.

If they are reused, can we assume that their Init() method is actually a pseudo event handler for application start event? The thing is we can't attach to application level events within http modules. But if they are being reused we could use Init() as application start event and do whatever we'd put in global.asax instead.

Question,Can we assume that module's Init() method is called only on application start event? Could we use this assumption to i.e. register routes for applications whose global.asax codebehind we can't change? web.config is usually accessible and we can change it the way we want.Would this actually work?

Additional info,We can check HttpApplication code and check its InitModulesCommon() method. This one actually calls Init() of each registered HTTP module. What is more interesting is that this method is only used by InitIntegratedModules() and InitModules() methods. Which are both used only in HttpApplication.InitInternal() method. This is the basis of my assumptions, but I would like to know whether someone has abused IHttpModule.Init() for application start event.

View 3 Replies

MVC :: Application_start Event Called Multiple Times In Application

Sep 15, 2010

In my MVC application ,I am updating my web.config at runtime through application_start event.So, ideally it should be done only when the application is started.BUT in MY mvc application the application_start event of global.asax is being called multiple
times , even when i have not restarted the application.

Its being repetadly called when i am calling different actions , so the webconfig is repetedly updating & making my application very very slow. what's the reason & how to handle this .

View 2 Replies

C# - Grid Data Bound To Stored Procedure Getting Called Multiple Times?

Mar 8, 2011

I have an application that uses an aps:GridView. The GridView is populated using a DataSource that calls a Stored Procedure. The DataSource passes parameters to the Stored Procedure based on some text fields. The page has been running slower than wanted, so I was doing some checking.

I ran SQL Profiler while loading the page, and saw the Stored Procedure was being called twice. I stepped through the code and found out that in the Page Load Complete event was where this was happening. In this event, I set the value of a parameter for the Stored Procedure, then did a DataBind on the GridView to pick up the data. As I was stepping through the code, I watched the SQL Profiler. When I got to the step of setting the parameter, the Stored Procedure had not yet been called. When I stepped through that and got to the DataBind command (before running that step), the SQL Profiler showed that the Stored Procedure had been called. Then I did the DataBind and the StoredProcedure was called again.

My question is, how do I get the parameters set, and get the GridView data bound, and only call the StoredProcedure once? If I comment out the DataBind step, the StoredProcedure never does get called (which seems really strange to me...).

View 1 Replies

SQL Reporting :: Using ReportViewer.LocalReport.Render() Method To Export Single Report Multiple Times?

Oct 21, 2010

I'm using the ReportViewer control on my .aspx page which displays a single report based on various user parameter selections. Dropdown2 is dependent on the DropDown1 selection (i.e. the user selects Unit A from DropDown1 and that results in 10 selections under Dropdown2, or the user selects Unit B from DropDown1 and that results in 15 selections under DropDown2, and so on). The user makes the selections, clicks the "Run Report" button, and the report displays as expected. The user then can export to Excel or PDF

I've received a request to allow users to run the report for all possible selections and export to their desired format rather than having to run the report for each separate DropDown1 and DropDown2 selection. So in other words, they don't even want to see the report on the screen, they just want to be able to click a button that runs the report for all possible parameter selections and export it to a single Excel or PDF document.

View 1 Replies

MVC :: Controller Base Class Initialize() And OnActionExecuting() Not Called When Unit Testing?

Nov 16, 2010

I'm using a simple base class for my controller that sets a piece of ViewData and makes use of the HttpContext. My understanding is that I need to put this code in Initialize() or OnActionExecuting(). I tried both, but believe Initialize() is what I want.

This works when running the app in VS just fine.

I wrote a unit test that calls the action and checks the ViewData for the expected value. When unit testing, neither method is called.

View 2 Replies

Error While Adding Dynamic Data To An Existing Web Site - The Method 'Skip' Is Only Supported For Sorted Input In LINQ To Entities. The Method 'OrderBy' Must Be Called Before The Method 'Skip'.

Apr 13, 2010

I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error

"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "

View 2 Replies

MVC :: 3.0 Beta: IFilterProvider.GetFilters Called 4 Times Per Request?

Oct 20, 2010

I implemented a custom IFilterProvider derived from FilterAttributeFilterProvider and

registered it using a Unity based dependency resolver. (Pretty much as described on

Brad Wilson's blog.) While debugging, I noticed that IFilterProvider.GetFilters on my

custom class get called a lot. I counted 4 times per request.

Is this normal or am I doing something wrong?

I have a simple project that reproduces the behavior if anyone is interested.

View 1 Replies

Web Forms :: Login Page To Load 9 Times Each Time The Web App Is Called?

Feb 22, 2011

Using Forms authentication, for some reason my login page is called 9 times. it causes some browsers to show "too many redirects!". Even with no javascript and nothing in the page_load event, it is called 9 times.

View 2 Replies

State Management :: IPartitionResolver.ResolvePartition Called Many Times Per Request?

Jan 6, 2011

I have a .NET 3.5 web application that uses SQL Server for its session state store. To improve scalability I wrote a class that implements IPartitionResolver that figures out which instance of SQL Server to use for a users session. All of this works great
and just as expected.

However, when I was debugging one day I set a breakpoint at the bottom of the ResolvePartition method to make sure the correct connection string was being returned. To my surprise this breakpoint was hit many (~5-10) times per request! The same is true about breakpoints in the IPartitionResolver.Initialize method.

Does anyone know why this is? It seems to me that you would only need to call these methods once per request. It's not like the users session is going to move to a different instance of SQL Server mid request.

View 1 Replies

C# - Where Is The Component Initialize Method In 3.5

Jan 10, 2010

I want to create my own naming convention for page events rather than AutoEventWireUp but I couldn't find Component Initialize methods any where ? Should I override it ? But in which class it is defined ?

Edit :

For example : I don't want to use Page_Load but LoadThisPage naming. So It should be like

Load += new LoadThisPage(sender,e);

I was expecting a InitializeComponent method where I can initialize page,controls etc. events handlers...But it turned out to be Constructor function :

So what confused me is I thought there should have been a method like InitializeComponent which does things for me already created by Designer itself so I thought I could define my own event handler names within this method by overriding it in the say Default.aspx.cs .

View 2 Replies

ActiveRecord Initialize Method In Application_Start?

Dec 20, 2010

I have a site that uses ActiveRecord. I'm getting an exception that says "An ActiveRecord class () was used but the framework seems not properly initialized. Did you forget about ActiveRecordStarter.Initialize() ?" This is a web application, and the Initialize() method is called by the Application_Start event handler.

I created a new page that also calls the initialize() method. If I visit that page once, then the rest of the site works. If I visit it a second time, I get an exception stating that the Initialize() method can only be called once.

I've tried modifying the web.config and resetting the application pool to force Application_Start to run.

This only happens in production; dev, my stage, and client stage are fine. Production is the only load-balanced environment--I'm not sure if that comes into play.

Edit: We have another site deployed in the same environment which successfully uses ActiveRecord with the same initialization code. One difference is that the site that is working has only the ActiveRecord code in Application_Start; the site that doesn't also sets up some URL routing in Application_Start.

View 1 Replies

MVC :: Stop Code From Executing In Initialize() Method?

Jul 29, 2010

in my controller I have code that validates URL. if not valid I want it to 301 redirect:

[code]....

but this still goes continues on and executes any code after. how would i simply 301 redirect? and NOT continue to process any code after break;?

View 3 Replies

Web Forms :: What Does Initialize() Does In Application_Start Method In Global.asax

Aug 13, 2010

In my company app they are doing the following. I do not understand that what initialize does? Do we need to Initialize assemblies before using them? and what kind of assemblies needs to be initialized?

Below is the code:

[code]....

View 2 Replies

How To Get A Listbox To Update After The Add Method Is Called

Mar 10, 2010

I am having a problem with getting a listbox to update after the add method is called. I am using an AsyncFileUpload control and as part of the AsyncFileUpload1_UploadedComplete I am creating a listItem and then adding that to the listbox. The item will not appear in the listbox. I have tried putting the listbox in an update panel and then calling the Update method on the panel from within the AsyncFileUpload1_UploadedComplete procedure and that too fails to update the listbox. I can call the Update method on the panel from a separate procedure and still the listbox will not update with the item added in the AsyncFileUpload1_UploadedComplete method.

View 6 Replies

JQuery :: AjaxStop() Method Is Not Called?

Jul 2, 2010

Below is my code, where the ajaxStop() method is not called.

[Code]....
[Code]....

View 1 Replies

C# - Run One Method 1000 Times In A Short Period Of Time?

May 28, 2010

Let's say we are building some public service that grabs the setup of a user (what server, user and pwd he wants to perform the call), logs in into that server and do some processing...

the process takes about 15 seconds to complete each user has a different setup (server/user/pwd), so the process needs to run against each one

if 1000 users tells the system to run the method at 1:00PM

How can I insure that the method is processed in the next 15 minutes?

What should be the correct approach to this little problem?

I'm thinking that I need to do something Asynchronously, and parallel processing could speed up things, maybe throttling the processes, maybe execute 100 calls per each 30 seconds?

I never did something like this and would love to get your feedback on ideas and future problems just to spend 100 hours of work and realize that I took a wrong road

View 2 Replies

Web Forms :: Why The Method LoadViewState() Is Not Called After The Postback

Sep 7, 2010

I can't understand why the method LoadViewState() is not called after the postback in my code below.After label1 cahnges its text the "__VIEWSTATE" hidden field is modified, but LoadViewState() is not called.

[Code]....

View 3 Replies

Controller Method Not Always Called From $.getJSON Request?

Mar 9, 2010

I have a controller method that returns a jSON object and in one calling situation, it works and in another calling situation, it does not work. When the URL in my browser is this:

http://localhost:65247/Client -- it works.

But, when my url looks like this:

http://localhost:65247/Client/UserAdmin?id=6 -- it DOES NOT work

In a nutshell, clients have users. From within the client, I wish to work on a specific user (this is the UserAdmin view). In this case, the client id is 6. From within the UserAdmin view that was launched with Id=6, I then wish to select a user from a dropdown. The idea was to use javascript and $.getJSON to fetch data for the specific user so as not to have to refresh the entire page. I use this approach in other parts of the app. The only difference I can see is with the URL in the browser. It would appear the presence of parameters via the '?' is futzing things up a bit.

View 1 Replies

Passing Value From Action Method To View From Where It Is Called

Mar 3, 2011

In one view (view1) there is a text box and a button beside it. i click on that button, i am popping another view (Create view) as a seperate window. in create view i am entering some values and creating a record in db. out of these values one value i have to send back to "View1". how can i send this value? i am opening view2 from view1 like

<input type="button" value="Get ID"
onclick="window.open('<%=Url.Action("Create","Controller1") %>',
'','scrollbars=yes,width=800,height=800,resizable=yes');"
/>

View2 contains some fields like Name,Email etc... and I click "Create" to call HTTPPOST. there i add the values to db including a generated guid. i want to send this ID to view1.

View 2 Replies

Web Forms :: Wizard.ActiveStepChanged Method Is Called Before The Page_Init?

Feb 1, 2010

I'm debugging right now and it seems the Wizard.ActiveStepChanged method is called BEFORE the Page_Init method?!?

I've tried it several times now.

If thats the case: what is called BEFORE Wizard.ActiveStepChanged?

View 3 Replies

.net - MVC LinkButton Equalization - Overloaded Index() Method Isn't Called?

Feb 4, 2010

I'm rewriting a Web Forms application as an exercise to learn some MVC skills.I have a number of LinkButtons on the original application which postback and raise a serverside event that rebinds data to a datagrid.

E.g.
Event handlers:
protected void lbtnOffset0_Click(object sender, EventArgs e)
{
[code]....

What I currently have in MVC is this:

<%= Html.ActionLink("CurrentYr", "Index", 0)%>
<%= Html.ActionLink("1", "Index", 1)%>
and

public ActionResult Index()
{
return View(MietController.GetMietByYearOffset(0);

[code]...
As the ActionLink renders an tag it doesn't postback so my overloaded Index() method isn't called. What are my options for doing this in MVC?

View 1 Replies

Web Forms :: Increment The Return Value Of Method Every Time It Is Called?

Jun 29, 2010

I want to use a function in the code file of ASP.NET such that everytime the function is called, its value increases by 1.I thought of a way but it didn't fully work out. I created a class for this and used a static variable in that but the lifetime of static variable in asp.net is till the time the app does not close.

public class Class1
{
public Class1()[code]....

View 11 Replies

Web Forms :: Code A Time Delay Before The Next Method Is Called?

Mar 13, 2011

How code a time delay before the next method is called? I have the following but I don't think it's waiting 10 seconds before calling CallMethod(). Thread.Sleep(10000); CallMethod();

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved