MVC 'Find' method taking a long time (even in release)? (Using miniprofile) - c#

I'm using MiniProfile to try and figure out why my MVC site is taking a long time. It looks like the 'Find' method is where the time is being spent. I have read a couple things on this and most people seemed to suggest that it was due to having <compilation debug="true" .. > set in the web.conf. I can confirm that in the following example the debug is not set (my compilation looks like the following):
<compilation targetFramework="4.0">
...
</compilation>
No where is debug mentioned. But yet, my find calls are taking upwards of three seconds :S
Any suggestions on how I can figure this out? (Note: I am running on an Azure production server. I have RDC'd into the system to confirm that the pushed web.config does not contain the debug="true").

If this is the first request coming to your website after publishing or after the AppDomain has been brought down by IIS it is normal that the Find method takes a long time. It will then cache the location for this view and on subsequent requests it should be much faster. Try Ctrl+F5ing in your browser on the same url.
Also try explicitly setting debug="false" in your web.config.

Related

Random Invalid Viewstate Error

I know there are a lot of questions on this topic and I have read them all.
I'm using IIS8, .Net 4.5.
Users randomly get an invalid viewstate error, I can't figure it out. Once this happens the only way they can get back into the site is to clear browser cache.
In my web.config I have:
<system.web>
<machineKey validationKey='....key here' decryptionKey='....decrypt key is valid here' validation='SHA1'/>
<!--<hostingEnvironment shadowCopyBinAssemblies="false" />-->
<authentication mode="None" />
<compilation targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
...
</system.web>
I'm running on a virtual private server, and I've yet to find a viewstate larger than 9kb.
My application pool is set to restart at 3:00am, once per day.
My page uses update panels, maybe the user is clicking 'back'? But I've seen it happen just visiting the page with no clicking back.
One thing I noticed is I have 3 different sites using the same application pool identity, but the application pools are seperate. There is no machine keys in machine.xml, but only in my web.config.
A couple of possibilities to investigate:
Update panels are changing form field values (which are what is used to compute ViewState), then the page gets POSTed back to the server, where the new values make validation fail. See this post
You have caching enabled (perform a trace of HTTP headers - make sure you don't have dev tools open) which is causing invalid ViewState to be generated w/ UpdatePanel gumming things up.
Are you using Server.Execute anywhere? (see above link for same)
(less likely) Does your "Virtual Private Server" get migrated to different hardware (perhaps without you knowing it)?

Wcf rest service URL max length

I have rest wcf service working okay.
Except in some scenarios It throws bad request.
On some search and checks, it seems when the url has longer parameters.(sometimes url length is more than 1000) .It does not hit the service and thrown bad request straight away.
http://testservice/Service.svc/endpoint/get/1/2/longparameter
How can I address for such situations?
I had a similar issue and thanks to this answer was able to resolve it by adding the following:
<system.web>
<httpRuntime maxUrlLength="500" />
</system.web>
That worked for me, but in your case it sounds like you'd need to set it even higher.

logging off a user when the session times out

I am creating a mvc4 application and here I am creating a cookie to give a user access to various pages depending on their roles and things. but I have different doubt. Instead of logging off people generally tend to close the browser window. So, I made the cookie not store any of the data from the login when that happens (or I think thats what happens, according to the blogs and answers Ive read so far!)
I only want 10 users to access that site at one time. So when the user closes the browser or when the session ends I want it to execute the LogOff function that keeps track of the number of people logged in and opens up that port session for use by someone else.
I tried adding session_end in the global.asax page and it just never seems to get there. and for testing purposes I had it expiring in a minutes time. But it does however go to the Session_start in the same global.asax page.
Any idea as to how I can get this to work?
This is what I had to do (hoping its not silly!):
In the web.config, needed to add the timeout here to trigger session_end
<system.web>
<sessionState mode ="InProc" timeout="10"/>
</system.web>
Although, in the same web.config there is a timeout here, i dont know where it goes.
<authentication mode="Forms">
<forms loginUrl="/SiteUsers/Logon" timeout="10" />
</authentication>
If you guys have other ways to get around this, please do tell me, im all ears! Im still in the trying and testing everything phase so any help will be much appreciated :)
Thanks guys! hope this helps solve someones problem.

Session expired before timeout

I set sessiontimeout in web.config file like following.
<sessionState timeout="120"
cookieless="false"
mode="InProc"
/>
Some times above code working fine.But many times session expired after 10 to 15 minutes automatically.
and this errors exists in every browser.
when i run same application using .net on my local computer it working fine.
Please note that, i haven't create global.ascx file yet.
Sessions will also be reset when the application recycles. This will happen when you change some things in the site, like change anything in the "bin" folder or modify the "web.config" file.
Also IIS may stop or recycle applications that it thinks are not used at the moment.
Are you sure you want to keep everything in memory for two hours, even after the user left? Better ways to keep the session alive would be to use some regular (every few minutes) AJAX callback. Search for "session keep alive asp.net ajax".
Have you verified the session timeout the app is ending up with? Do a response.write of Session.Timeout. This value can be set in several places.
How do you know the user is being active? The session will time out if he's only typing text, scrolling, and/or reading for lengths of time greater than the timeout value. The browser must invoke a HTTP request to the server to reset the timer.
As Hans mentioned, a background script-based "pinger" set to run at interval to access minimal web content will help.
Considering I'm about to start yet another web application, and I seem to need to add this functionality to most web apps, I was inspired to create a little package called Keep Me Alive to speed this process up in the future. You can find it here:
http://kma.codeplex.com/
Hope it helps!

Raise the time-out for a single webservice

My web configuration looks as follows:
<system.web>
<compilation debug="false"/>
<httpRuntime executionTimeout="90"/>
</system.web>
This is fine for most webservice functions but one function has a query that is running a very long (5 minutes) time and will be stopped before it has finished. Is it possible to set the runtime to 5 minutes for this webservice alone?
E.g.:
MyWebServices.asmx?op=WS_LongMethod --> Timeout of 5 minutes
I've thought about running the database query async (fire and forget) but it doesn't seem possible with sybase/oracle through ODBC.
Yes, you can do that. In the web.config, you'll need to add a <location/> element:
<location path="Path_To_Your_Service.asmx">
<system.web>
<httpRuntime executionTimeout="90"/>
</system.web>
</location>
The <location/> element gives you a mechanism whereby you can apply web.config attributes to specific paths within your site.
You can use a delegate within your webservice to call another method asynchronously. Within this method you can do your database IO. This means you will return to the caller before the operation is complete, however if you generate a unique ID and store any info related to that ID, then you can retrieve it at a later date.
Did you check the .Timeout property of web service?
Indicates the time an XML Web service client waits for a synchronous XML Web service request to complete (in milliseconds).

Categories

Resources