Slow first Time in ASP.NET applications

19. March 2013 12:19 by Mrojas in ASP.NET  //  Tags: , , , , , ,   //   Comments (0)

Well, this is a recurrent topic with ASP.NET:Why is the first page load always so slowjQuery152032498610322363675_1363786231988?

I don't think there is a definite answer but I can think on some explanations:

  • ASP.NET applications by nature exhibit some degree of delay upon initial access to the site. This can be due to JIT compilation, caching, etc. 
  • Note that it is also a common effect on some sharepoint sites. 
  • Some people on StackExchange attribute this slowness to: " The IIS application pool is shut down after 30 minutes of inactivity. After that, when you make a request IIS basically has to start the website up again, which leads to the behavior you are describing. You can change the idle time of your website in iis though to avoid it." 
Workarounds
 
 
There are some workarounds for this situation:
 
For some years there has been a warmup script that you can use on pre-vs2010 apps:
 

ASP.NET Site Warm up on GitHub

 
And there is  even an IIS addin for that, the following blog provides some references about this addin:
 

ASP .NET Pre heating and the App Warmup Addin for IIS

 
These problem is so common that now in VS 2010 there is even an auto-start feature that you can use:

Auto Start Feature in ASP.NET 4

 
 I hope this links help and I'll add more explanations as I find them. Please feel free to comment.

Share session state between ASP classic and ASP.NET or missing ASP classic and ASP.NET

31. January 2013 19:10 by Mrojas in ASP.NET, ASP  //  Tags: , , , , , , , ,   //   Comments (0)

Today my good friend Jafet asked me: "What do you think about sharing ASP classic and ASP.NET state?". And I told him that there were some projects for helping in this task.

I will mention some of them here.

The first one is NSession. This project provides an implementation that allows you to use the ASP.NET state server in ASP classic. You do not have to change your ASP classic code.

"You need to instantiate one of the COM objects in your ASP classic page before it accesses session state, either:

set oSession = Server.CreateObject("NSession.Session")

or

set oSession = Server.CreateObject("NSession.ReadOnlySession")


If you instantiate NSession.Session, the session state in the session store will be transferred to the ASP Classic session dictionary, and an exclusive lock will be placed in the session store. You do not need to change your existing code that accesses the ASP Classic session object. When NSession.Session goes out of scope, it will save the ASP Classic session dictionary back to the session store and release the exclusive lock.
If you have done with the session state, you can release the lock early with

set oSession = Nothing


If you instantiate NSession.ReadOnlySession, the session state in the session store will be transferred to the ASP Classic session dictionary but no locks will be placed."

The second option is SessionService. This project provides a mechanism for sharing the state between ASP classic and ASP.NET by serializing state data to an SQL Server.  The project page provides detailed information on how to setup IIS, how it is used in both platforms.

 

And the third option is a very interesting one called ASPClassicCompiler. This is a great great project. It provides a mechanism for compiling the ASP classic to .NET. This project is now opensource and we need to thank Li Chen for it.

 

Great ideas can be implemented thanks to this source. For example Brian Ellis suggested using the VBScript engine to replace the  MSScript.OCX. Another great one is an implementation of an View Engine that can be used with MVC and which support ASP Classic.

I really like the ASPClassic project and will be posting some interesting examples soon (as soon as I finish watching some Dr. Who episodes and the last Fringe season :) ) 

Problem uploading large files in ASP.NET

12. October 2012 10:35 by Mrojas in ASP.NET, C#, Cloud, General, HTML5, SQL Server, VB6 Migration  //  Tags: , , , ,   //   Comments (0)

If you try to upload large files you might get an exception like

HttpException: Maximum request lenght exceeded.

This problem occurs because the default value for the maxRequestLength parameter in the section 

of the machine.config or Web.config file is 4096 (4M).

So any file with a size bigger will fail.

However I think that the max size that you can write here is 2G 2097151

Some info can be found here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

 

So to change that for 512mb use something like:

 

<configuration>

    <system.web>

        <httpRuntime maxRequestLength="524288" /> 

    </system.web>

</configuration>

VB6 Migration, HTML5 Forms and ASP.NET Web Forms

16. February 2012 11:02 by Mrojas in HTML5, VB6 Migration  //  Tags: , , , , , , ,   //   Comments (0)

VB6 Migration, HTML5 Forms and ASP.NET Web Forms

If you come from a VB6 background, and your application is still in VB6,
you are probably wondering that this might be a good time to move out of VB6.

But is also a complex time. Which is right path: WinForms, Silverlight, WPF, HTML5?

Choosing the right target platform can be very tricky and depends on many varaiables.
So let's assume in this post that you have already decided that you want to use Web Tecnologies
and why not HTML5 as well.

ASP.NET Web Forms is a good technologie and developing forms with it is also very easy,
but can you develop HTML5 applications with this?

Well Brandon Satrom has a nice column in MSDN Magazine about Web Forms with HTML5 Forms.
He says:


If you’re planning to do HTML5 Forms development with ASP.NET Web Forms, there’s good news:
Many HTML5-related updates to .NET and Visual Studio are being released out-of-band, so you
don’t have to wait for the next framework version to use these features today.

To get started with HTML5 Forms and ASP.NET Web Forms, you’ll need to grab a couple of updates.
 First, make sure you have Visual Studio 2010 SP1 (bit.ly/nQzsld).
In addition to adding support for new HTML5 input types and attributes, the service pack also
provides some updates that enable you to use the new HTML5 input types on the TextBox server control.
Without this update, you’d see compile-time errors when using the new types.

You’ll also want to grab the Microsoft .NET Framework 4 Reliability Update 1 (bit.ly/qOG7Ni).
This update is designed to fix a handful of problems related to using the new HTML5 input types
with ASP.NET Web Forms. Scott Hunter covers a few of those—UpdatePanel, Validation Controls
and Callbacks—in a blog post from early August that you can check out at bit.ly/qE7jLz.

Update:

Mobilize.NET and Artinsoft.com company now helps in the HTML5 migration problem from VB6, Windows Forms and PowerBuilder. http://mobilize.net/default.aspx

 

Getting the IP Address of the client in a Windows Azure Role

Are que getting null or empty with some Request.ServerVariables

When you convert your ASP application to run on Windows Azure it is a good
to put attention to the methods that are used to get the user IP Address.
Normally the recommendation will be to use Request.UserHostAddress however
our friend Alex has found that this property can return null or empty.

After some research Alex found that there are several scenarios under which
you must check both the REMOTE_ADDR and the HTTP_X_FORWARD_FOR server variables:

More info:
http://forums.asp.net/t/1138908.aspx and
http://meatballwiki.org/wiki/AnonymousProxy

A possible code snipped that can provide a value for the client address can be:

public static string ReturnIP()
        {
            var request = System.Web.HttpContext.Current.Request;
            var ServerVariables_HTTP_X_FORWARDED_FOR = (String)request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            var ServerVariables_REMOTE_ADDR = (String)request.ServerVariables["REMOTE_ADDR"];
            string ip = "127.0.0.1";
            if (!string.IsNullOrEmpty(ServerVariables_HTTP_X_FORWARDED_FOR) && 
                !ServerVariables_HTTP_X_FORWARDED_FOR.ToLower().Contains("unknown"))
            {
                ServerVariables_HTTP_X_FORWARDED_FOR = ServerVariables_HTTP_X_FORWARDED_FOR.Trim();
                string[] ipRange = ServerVariables_HTTP_X_FORWARDED_FOR.Split(',');
                ip = ipRange[0];
            }
            else if (!string.IsNullOrEmpty(ServerVariables_REMOTE_ADDR))
            {
                ServerVariables_REMOTE_ADDR = ServerVariables_REMOTE_ADDR.Trim();
                ip = ServerVariables_REMOTE_ADDR;
            }
            return ip;
       }

In the previous code the HTTP_X_FORWARDED_FOR value is examined first and if it is not null or unknown then ip address of the client
is gotten from there.

Windows Azure and Websites in a Flux

1. May 2011 07:47 by Mrojas in Azure  //  Tags: , , , ,   //   Comments (0)

Windows Azure is a great platform and the escalatity oportunities are great,
and deployment time is also great.
You can have all your website up and running in just 10-15minutes.

But… and yes there is always a but.

Sometimes you can have a WebSite that is not that static, that as a matter of fact
you are changing its views constantly. Specially if some ideas are not finished.
And yes you can test locally, but there is also a situation where you might want to have that flexibility.

Well looking around I found a very interesting solution by
Maatern Balliauw. http://blog.maartenballiauw.be/post/2009/06/09/A-view-from-the-cloud-(or-locate-your-ASPNET-MVC-views-on-Windows-Azure-Blob-Storage).aspx

What he proposes is to use windows azure storage as a virtual file system, so you can with simple tools
like the Windows Azure Explorer modify your web pages without the need of going through a lengthy republish process.

So go ahead and keep enyoing Azure

IIS targetFramework not supported

31. January 2011 10:55 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

 

I had a situation where the IIS reported that the targetFramework=4.0 attribute
was not supported.

I’m not sure why it started reporting it, but I fixed it with this:

%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i

ASP to ASP.Net Migration: Fixing Includes

24. January 2011 08:43 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

During a migration from ASP to ASP.NET one of the biggest hurdles is finding a way to deal with the include files.

ASP was a interpreted environment whether ASP.NET is compiled and this difference is very important because you need to find ways more natural in .NET to do some things you used to do in ASP.

For example in ASP you used to have a set of common functionality that was included in your files. What will you do with that?

For ASP ASP.NET in VB.NET is a lot easier. One of the things you can do is move all those common subs and functions to a Module.

Now if what you have is a ASP.NET Web Site, then just your new modules to the App_Code folder and voila your pages are now able to see that code.

For a ASP.NET Web Application is just a little differente. What you have to do is move your common variables, constants, subs and functions to a Module, but that is not enough to make that code reachable from your mark up, so you have two alternatives:

1. Add an %@import Namespace=”QualfiedNamespaces.Module1”  statement for each of your modules.

2. Modify your web.config file and add under system.web something like:

<system.web>
              <pages>
                     <namespaces>
                           <add namespace="WebApplication1.Module1"/>
                     </namespaces>
                     
              </pages>

That will add an implicit import for all your pages.

For C# it can be a little more complicated. Because you do not have modules like in VB.NET, what you can do is use extension methods, to have a similiar syntax.

Could not load file or assembly ‘App_Web_ ….

16. December 2010 04:53 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

If you ever get an error like, it is an annoying situation where the web server is trying to use and old compilation of your aspx files.

The workaround I have is: rename web.config to stopweb.config.

Browse to the offending page URL it will return an error. After you receive the error rename stopweb.config to web.config

Browse to the offending page. This will force the server to compile the web pages.

And if it work the problem will now go away.

Migrate JSP to ASP.NET MVC

14. December 2010 06:19 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

ASP.NET has gone a long way. And it might be the right time to start moving your sites to ASP.NET.

But what happens if you have a big investment in JSP. Will I lose all my JSP skills?

Well ASP.NET is not the same as JSP but the MVC view engine concept can help you retain some of the JSP flavor.

A good MVC View Engine project is SharpTiles this project provides a partial implementation of JSTL and Tiles.

Just take a look at the the SharpTiles. Just as they say SharpTiles if for you if “You are a Java Developer and you don’t like .aspx”