Posts tagged ‘ASP.NET’

FireFox is Slow When Using Visual Studios ASP.NET Development Server (Cassini)

If you’re ever running a web app locally in Cassini (Visual Studios built in web server) and FireFox is really really really slow, but IE is fast like it should be, then you probably need to turn off IPV6 in FireFox.

To do this, type “about:config” in the address bar and filter on “v6″. Turn off IPV6 and FireFox should be fast again.

ASP.NET Magic Maintenance Mode

I just recently found that you’re able to easily put your ASP.NET website int “maintenance mode”. All you need to do is add an App_Offline.htm file to you site root, and ASP.NET will serve up all requests to that file. Just rename or remove the file when you’re down with your maintenance.

Scott Gu has a couple good posts on this.

http://weblogs.asp.net/scottgu/archive/2005/10/06/426755.aspx

http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx

DevConnections – Inside Partial Rendering

This talk was given by Dino Esposito.

This talk was once again flooded with entry level questions from the same person who ruined a few other sessions I attended. Dino did a good job of answering them quickly, and trying to move on. This guy just wouldn’t shut up though…

Basically, there are 2 approaches to ASP.NET AJAX. You can use script services, which is the javascript library directly. Or you can use partial rendering, which is a set of new controls that handles all the guts for you.

Dino went into some detail about how the update panel works internally, but I had already got an in depth talk about it from Eilon Lipton, the person wrote wrote the update panel, in a previous session.

A couple interesting things I caught are; There are page lifecycle event methods, such as "function pageLoad()", just like in ASP.NET. There is an easy way to do getElementById on an ASP.NET control (which has a dynamic client id generated). You just use $get() instead.

DevConnections – Dealing with Long Running Requests in ASP.NET

This talk was given by Rick Strahl.

What is considered a long running request? When it overruns the max thread pool, is CPU intensive and runs for more than a couple seconds, or it has a high user count.

There are 100 threads per CPU in the ASP.NET request pool. This works differently if you’re using IIS6 or IIS7. With IIS6, threads originate with ISAPI. Win32 native threads are fed into the ASP.NET engine, then released back to IIS. With IIS7, there is an integrated pipeline. IIS threads fire directly into the ASP.NET pipeline. There is no difference between an IIS and ASP.NET thread.

There are several scenarios (solutions) Rick talked about, to handle long requests.

Scenario 1: The app is busy interface.

This is basically a "fake it" solution. You do something silly like disable buttons and show a progress bar to people know there is something happening but have to sit and wait. You disable the interface so the user doesn’t click again. A new click will cancel the current request on the client and start a new one. The request on the server will keep running though, and take up resources.

Scenario 2: Async processing.

This works well for I/O bound processing, but not for CPU bound processing. ASP.NET (2.0+) has things build in to make this easy. You can use page async tasks, and async operation callbacks. This will return the thread to the pool while waiting. When the request comes back, it grab the thread from the pool, and continue. Basically your page will run it’s course while the async stuff is happening, but won’t be rendered until all async tasks have returned.

Personally, I think this is a nice way to do it. You can keep firing off new async events when another finishes, so if there is a request that takes some time during the async work, the other requests won’t be affected by it.

Scenario 3: Threads and delegates.

This works well in the run and forget scenarios. ASP.NET disconnects from the thread, and continues processing the page, including rendering the page. If there is a task that you don’t want to block your page from rending, and you don’t need any information back from it, such as logging or writing something to SQL, this is a great way to do it.

Scenario 4: Background scheduling.

You can queue your requests or have non ASP.NET threads do the work. He didn’t talk much about this option. It doesn’t seem like something that would be used all that often.

Scenario 5: Async messaging.

You can use message based communication. Store your message somewhere, like SQL, and check back to see if the task is completed. This would be used in conjunction with the "app is busy interface" method.

If you have a site that uses services, is CPU or I/O intensive, or is just slow, Rick had several good ways of possibly speeding up your application. There are other things to consider also. If you’re using SQL, make sure indexes are set correctly, queries are optimized, and if you’re db is hit hard, putting the db and the log on separate drives, or even going as far as writes and reads are in separate db’s.

If you want to know more about async pages in ASP.NET there is a good MSDN article on it.

DevConnections – Architectural Decisions for ASP.NET

This talk was given by Michele Leroux Bustamante.

Michele went into a lot of detail about implementing globalization in ASP.NET. I have not done any globalization yet, so this was pretty much all new to me.

There are a few way you can do this. You can duplicate all the data and pages in each culture. A better way is to put all the culture strings into a resource, and pull the right one based on the user’s culture. You can use resources to manage assemblies, images, string, and more.

You can set the current threads culture based on the setting of the user’s web browser, or by a user setting. A user setting would be letting the user select the culture they want.

Her suggestions for globalization is, if there is any chance that you may need it, plan for it up front. You’ll save yourself months of rework.

She talked a little about output caching and the ways of doing this. ASP.NET kernel caching has 10x performance gain, where as user caching has 3x performance gain.

She talked about distribution of functionality. This is something I’ve heard that is a good thing to do, but no one has given me a reason as to why. Michele explained this quite well.

You should consider using a service boundary for security purposes. Instead of using a n-tier architecture, call a service that does the data access. This way, if a hacker compromises your site, they’ll only be able to go through your service, and won’t be able to access your data directly. To reduce the attack surface, use role based access for your service methods. Run with least privilege.

AJAX can only use HTTP services, so if you want to be secure, use a "router" service. The router will forward requests to the real service. Then you can verify that the request came only from the router.

Michele talked about load balancing considerations; what to do, and what not to do. I’ll write the to do here. Create new proxies and cache the channel. Limit downstream service calls.

Michele went in detail on these subjects and had many examples. I just touched the surface of her talk here.

DevConnections – Building Real World Apps 3 of 3

This talk was given by Scott Hanselman and Eilon Lipton.

They did mostly examples, so I don’t have much to write about.

  • They went into depth about how the update panel works. Eilon wrote the update panel, so it was interesting hearing him explain the internals of how it works. It basically will take all the code inside the panel, do an async request, and replace the code with what is returned from the request using the DOM.
  • They talked a little about the ASP.NET AJAX Control Toolkit. Check out the site for more info. They can be pretty useful.
  • With the script manager, you can enable page methods, and it will "export" .NET methods into Javascript.

DevConnections – Building Real World Apps 2 of 3

Scott Guthrie gave this talk.

Scott demonstrated one of the new controls in ASP.NET, the ListView. This is similar to the GridView, but you have complete control over the markup that is created. From the look of it, it pretty much obsoletes the GridView and the DataGrid; possibly the repeater too. There is a DataPager control that is used for handling custom paging, and many more.

There were great improvements with Javascript in 2008. Javascript has full intellisense support now. It uses type inference, so if they type of a variable changes, the intellisense is updated to reflect that. Intellisense works against JSON enabled ASMX services. If you create an object from a service, the intellisense will retrieve data from the service and updated itself. XML comments now work with Javascript methods and show up in intellisense. You can reference another Javascript file so intellisense will work with libraries that aren’t contained in the current file.

/// <reference path="MyJavascript.js" />

IIS 7 which is being released with Windows Server 2008, and already include on Windows Vista, has many new improvements.

  • Uses a web.config model. All values in IIS can now be set inside the web.config file.
  • Has on-demand tracing.
  • Web farm support is built in.
  • Has a new admin tool.
  • Supports 1,000’s of sites.
  • Role based management is built in.
  • ASP.NET is now integrated instead of being an ISAPI filter.

DevConnections – Building Real World Apps 1 of 3

The talk was given by Scott Guthrie. He did all his examples live from scratch as usual. He’s one of the few people I’ve seen that does this, and his stuff always works. All hail The Gu.

Scott always has a nice style to his sample pages. He said he likes to go to a site that has a style he likes, and steal the style… legally of course. One site he likes to use is http://www.opensourcetemplates.org.

Btw, I’ll only be blogging about things that I found interesting.

  • Nested master pages finally works with VS 2008. This works with .NET 2.0 also if you build it with VS 2008. The only reason it didn’t in 2005 is the IDE.
  • When building data solutions with LINQ-to-SQL, you can either create the business objects and choose create schema to have the database and tables generated, or you can create the objects from an existing database schema. If you update the object model, you can save the changes back to SQL. If SQL changes, you need to "refresh" the object model to have the code regenerated.
  • LINQ can do either eager or lazy loading and does lazy by default. Eager loading means it will make a SQL call every time a query expression is written. With lazy loading, the SQL call doesn’t happen until the data is needed, so all the calls are batched into one SQL call. This is a really nice feature.
  • LINQ-to-SQL handles text input for SQL injection so you don’t have to worry about doing it yourself. Much like how a using parameters in a stored procedure would.
  • LINQ-to-SQL has optimistic concurrency built in. This is another great feature, and is something that is complicated to implement by hand. If you try to persist your data, and the row has been updated since you got the data, it will let you know so you can handle it properly.

LINQ and LINQ-to-SQL (or LINQ-to-Entities) are going to quickly become the standard for data access, much like generics have become a standard. I’m looking forward to utilizing them in my projects.

DevConnections – ASP.NET Keynote

I’ve been meaning to blog all the sessions I’ve attended, but I’ve been quite busy, so I’m a couple days behind.

The keynote was given by Scott Guthrie; aka "The Gu". Scott is just an amazing speaker. It’s a treat being able to hear him speak in person. He’s very comfortable when he talks, he really knows his stuff, and he likes to code on the fly for his presentations. Here are some of the points he talked about; without going into too much detail.

  • IIS 7 will be coming in the first quarter of next year.
  • VS 2008:
    • Office integration with Windows apps.
    • Multi-targeting.
      • Targets .NET 2.0, 3.0 and 3.5.
      • When changing targets; references, the toolbox, intellisense, project types, and more are updated.
    • Split view window for designer and code.
    • ASP.NET AJAX is integrated.
    • Javascript has intellisense and debugging.
    • Rich CSS and HTML designer with intellisense.
    • LINQ and rich data support including the LINQ-to-SQL ORM.
    • Same WYSIWYG designer as the expression tools. This has been greatly improved. It’s now very fast when switching between the design and code views because it’s running the design live instead of rendering when switched.
    • CSS designer shows style hierarchy, similar to FireBug and the IE Developer Toolbar. This is a really nice feature.
    • Click once improvements.
    • WPF WYSIWYG designer built in.
    • WinForm integration with WPF and vice-versa.
    • Office support built in.
      • Ribbon extensibility.
      • Outlook region support.
      • Task pane.
    • Workflow designer with integration with SharePoint.
    • WCF tool support.
      • WCF service consumption.
      • WCF host containers.
      • Syndication support (RSS).
  • Silverlight:
    • HTML DOM integration.
    • Robust networking.
    • Flexible data support.
    • Multi-language support.
    • High performance runtime.
    • Rich UI controls, graphics, media, and interactivity.
  • Silverlight 1.1:
    • Runs somewhere between 20-200 time faster than the Javascript version.
    • A chess game had 1,500,000 nodes (or moves) looked ahead, and the Javascript version only had 1,500. Needless to say, the .NET version always wins when they play each other.
  • Source code for .NET Framework libraries is available for debugging. This includes the base class libraries, ASP.NET, WPF, WCF, WF and LINQ.

The 2008 release, which is due in the next couple weeks, is just amazing. There are so many features that will make development a lot better, that’s it’s crazy not to switch the day it comes out. Many of the features are available for .NET 2.0 projects. I overheard a person talking about how his team still uses .NET 1.1, so all these features are useless to him… why was he at the conference then? He also said the doesn’t understand why people would use the MVC/MVP pattern, and how MS pushes all these technologies they don’t use themselves. How long has MFC been around? Hmm… I think he may be wrong.

Web Service Session Trouble

I had my first attempt at creating a web service lately. Everything went fairly smooth. I stuck to the Web Service Software Factory pattern in the MS patterns and practices, but didn’t use the actually code generation.

I got stuck when trying to use Session in the service. What a pain. First I needed to enable session state in the web.config. Ok. That’s a given.

Next I needed to set EnableSessionState = true in the WebMethodAttribute for every method that needs session. Ok. Not too bad. It’s fairly well documented, and was easy to find.

This next step is what stumped me. I still couldn’t get Session to work for the life of me. I found that every time a service method was called, the Session of the service had a new SessionID. This was driving me nuts. I searched for a while and found a few people saying to use CookieContainer, and a couple examples. None of the example made much sense, and they all looked like they were trying to save the service session across postbacks of the client application.

I decided that I would look into CookieContainer on MSDN since a few people mentioned that needed to be used. BINGO! This solved my problem.

http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.httpwebclientprotocol.cookiecontainer.aspx

Basically, you create a CookieContainer on the proxy of your service. Then when you request something from the service, the service has a place to save it’s sesssion (the CookieContainer).

I don’t know why this isn’t and can’t be built in.

Oh well. Now I know better.