Odd (Slow) Behaviour in ASP.NET - c#

First off I would like to apologize beforehand, in case this turns out to be a really dumb question. I just can't wrap my head around it.
I have a C# ASP.NET website running with .net 2.0
Both on my local machine, as well as on production server it runs terribly slow.
Even if I disable ALL the code, it still runs slow to serve the page.
However, if it is a .ashx, instead of a .aspx it executes immediately; even if it executes the same things.
Any ideas?
Truly appreciated!

if your ashx page loads faster than the aspx, it might be related to the HttpModules or aspx page lifecycle custom code running on your application.
Check if you have anything in the Application_BeginRequest or other events in the lifecycle that could be writing to files (logs), connecting to slow databases or a authentication authority (like AD) that might be going thru the network and taking longer than usual to process.
Disable all the HttpModules in the web.config one by one and test. Check this great article to get more info

Are your .aspx pages defined as content pages for a Master page? Perhaps there is logic being executed in the Master.

Have you tried creating a new, quick Website on your local server to test the speed? Try creating a quick asp.net website and test it on the local server. If this new website goes fast, it may be something within your existing website that you're not aware of.

Is there any difference between the inbuild development server and your iis server?

Could it be a slow javascript? Ajax request? Is botht he asjx and aspx doing the same things?

Related

What would be the best way to generate website from db

We have a lot of red tape to handle before any changes to anything can be made on our servers. Hence I'm looking for ideas and/or suggestions for the below situation.
Must generate html from db (MSSql Server) for a static website hosted on IIS 6/7.
No (external) changes should be necessary on the server side except the ones the application/website makes itself.
I tried markdown and it generates everything nicely but I could not find a way to make the above idea applicable with it. I am willing to put all html code in the db for each individual page but it sounds awkward. Should I go with something ASP.NET'ish or a Windows Service or a standalone app to run at a schedule.
Thanks for the suggestions.
ASP.NET Dynamic Data might be your technology of choice.
http://msdn.microsoft.com/en-us/library/vstudio/ee845452%28v=vs.100%29.aspx
However, my advice is that you'll never be able to solve your problems by something like the above. You need to work out how to do releases more often - maybe start with a CI server and start scripting your releases if you haven't already.

Getting around the XSS filter in web browser control

I am working on a pet project and need to overcome a major hurdle in an application. I have checked countless forums and articles and have only found bits and pieces of what I am looking for, so I hope a more direct approach will help me.
Here's the scenario:
1. The site is actually a game, which uses Javascript/JSON with DHTML on a page that has several IFRAMES - two of which are deeper inside the outside page AND of a separate domain.
There are NO security issues with what I am trying to do. All programming and access is limited to merely simplifying and automating normally access functions only. All authentication and private information is done prior to any access, and only the session information will ever be used, and only to facilitate game operations that the user knows will happen.
The idea is to use the webbrowser control to access the game and provide ordinary access, while the app hosting the browser gets the game session information and makes separate automated calls to the game servers. This has already been done via Firefox using Greasemonkey scripting, and it works well - except that Firefox has a horrible memory leak that eventually causes the whole operation to break down.
The problem I am running into is obvious. I am trying to access the iframe that is technically on a different domain, and the web browser DOM model won't let me in. I have seen enough articles to know there are several workarounds to XSS filter blocks but they are quite vague and vary depending on scenario.
So, I will outline exactly what I need in hopes that I can obtain an amicable solution...
I need to obtain the DOM of a nested IFRAME of a different domain. If need be I could live with just the source, but the DOM and the JS vars would be the most ideal. My strategy here is to use the session information and make HttpWebRequest calls parallel to the web browser in-game. That way I can automate some functions while still playing. It can be done - if I can get the session information and pass it the same way. It will all be done on the same client with the users permission and knowledge, so no security issues.
I would really like it if I could pass information BACK to that IFRAME. One of the major things this project is trying to do is make some visual changes to simplify the look and feel of the interface. It is all in HTML, so changes would simply be adding some in-line styling of JS code...
So anyways, what ideas and suggestions would work best? At this point I am open to all scenarios, but ideally something as simple as possible to get what I need. This is already a huge project :).
Thanks in advance!
If you are in control of all sites in question, you could use postMessage to communicate. Also there is easyXDM which provides a set of transports that also work in older browsers (and automatically picks the best one).
https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
It's possible to bypass XSS checks and access iframes through IOleContainer, as described here. The sample is in C++, but it should not be a problem to do the same from C# with COM interop.

Running MVC and Umbraco 4.7 applications in parallel

We are using Umbraco 4.7.1 and it's very slow sometimes, taking more than 10-14 secs to load certain web pages.
Is it possible to create a new MVC web application and use this to display the slow pages instead of Umbraco? The important thing is that it should run on same web server and should replace a specific path currently existing in Umbraco, e.g. http://127.0.0.1/Product.
Any suggestions how to improve the performance are also welcome.
There are two parts to the answer. Firstly, yes you can. You can host the MVC application as an application within the site in IIS. You will need to ensure that you override all the web.config settings as these settings will be inherited. You will also need to add an the path of your MVC application to the umbracoReservedUrls and/or umbracoReservedPaths appSetting in the Umbraco web.config.
However, the second part of the answer is: don't.
Do not create and host a separate MVC application purely because you have performance issues in your Umbraco application. Figure out what is causing the performance issues and fix it. It sounds like you are possibly making too many calls to the database, or the calls that you are making aren't optimized.
My advise would be to run SQL profiler over the site on these pages and check what is happening. You should then review the indexes on the non-umbraco elements of your database, using views where appropriate, and also review whether you are using appropriate caching.

C# CGI executables - good or bad idea?

I would like to write a C# app to handle my HTTP (including AJAX requests) rather than go the PHP, PERL or ASP route as I just need to return some standard HTML, albeit obviously, as I want CGI, dynamically generated.
UPDATE: I am not proposing to write my own web server but have the exe hosted by a webserver such as IIS or Apache. Also I dont want to learn and use ASP (I know I can do it much faster, development time, myself in C#) and I just want W3C valid html sent back to the client.
Are there any good reasons for not doing this?
I realise each time a HTTP request is made the exe has to be loaded and run - but surely so does Perl, ASP and PHP? Is there a way to have an exe remain running dealing with all HTTP requests for specific page? (though it feels like I am just writing a mini HTTP server then!)
Are there any good tutorials? I have read this one, but it is bit dated (2005): http://www.codeproject.com/KB/cs/cgi_csharp.aspx
UPDATE2: I dont think speed is going to be a issue anyway (running a small exe without a GUI is almost instantaneous) but if I wanted to be really efficant I could write C# server then the non-static page requests can have a tiny exe written in C which sends the request to the C# server and returns the reply. Couldn't I? :)
There are solutions such as FastCGI, that eliminate the overhead of launching an executable every time you want to process a request. Very few people still use traditional CGI. I don't know if there is a solution compatible with .net.
There is a much better option for .NET, the System.Web.IHttpHandler class.
All you have to do is subclass IHttpHandler, and overload 1 method to process a request. In my opinion it is simpler CGI.
There is a good example on the MSDN Site.
I'd suggest leveraging the HttpListener API for this kind of thing if IIS really doesn't cut it for you.

URL Rewriting, Temporary Solution, ASP.Net 3.5

We've got a test site hosted only by IP address. We really need to test some functionality that depends on what subdomain someone is using to get to the site. But of course we can't even USE subdomains with an IP only site.
So, one thought I had was that instead of subdomains, we could have the testers open the site with a URL like this: http://192.168.0.1/smith or http://192.168.0.1/jones and I would then redirect them to http://192.168.0.1/default.aspx?site=smith etc...
Our testers are at the client, and asking them to enter in the querystring would be problematic. Plus, I'd really like to get a quick intro into URL Rewriting.
Can anyone give me any idea if what I want to do is possible, and if so, a pointer to some code or explanation or something?
We are using asp.net 3.5 and iis6, I believe.
Thanks for any help!
I wrote up an introduction to URL Rewriting in ASP.NET on my blog, for what its worth. Feel free to post more questions here to clarify any specific issues you have.
this will definitly work in your situation
http://www.urlrewriting.net/149/en/home.html
we have implemented same what you required is, its open source dll and you need to write some rules in web.config, according to your scanario, your rule something like
<add name="index" virtualUrl="^~/(.*)/Default.aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?site=$1&urw=t" ignoreCase="true"/>
you could possibly change the hosts file on the testing machine to point domains (and subdomains) at that IP, that way you wouldnt have to rely on DNS and could test as if the domains were assigned.
more information here:
http://labnol.blogspot.com/2004/10/tweak-your-windows-hosts-file.html
Using ASP.NET Routing Without
ASP.NET MVC
Using ASP.NET
Routing Independent of MVC
this is part of .Net 3.5 and is the
same mechanism used by MVC
This makes your life easy, due to the fact that everything is held in the HttpContext.CurrentContext.Items[""]
I have adapted this code for a few project where I have an XML configuration file. I then use this file to build the RouteCollection. This code has also been easily extended to handle 301 redirects for SEO.
This method is also loaded once in your AppPool and removes the need to parse xml files and configurations for every call. This so far has been the best solution for me performance wise.
If you need any assistance please let me know. I will gladly lend a hand.
Edit : 13/09/09
I have not run into that problem yet since I usually handle the membership / authentication verification in every page. I usually have a control or method I call on the page to validate/ authorize a user. My clients rarely use the ASP.Net membership, they usually rely on proprietary sub systems which we need to connect to.
I have extended the examples provided in the above links so that I can write one xml routing table which gets loaded when the application starts up or when I force a RouteCollection update.
so far this has proven itself to work pretty well.
this can also allow for a change in routes while the application is running, with no down time.

Categories

Resources