Arturito.net

Come to The Dark Side, We Have Cookies!

ASP.MVC 2 – How to migrate project from ASP.NET 2.0 .NET Framework 3.5 to ASP.NET 4.0 .NET Framework 4

without comments

So you have decided to move your ASP.NET MVC2 project  from the Windows Server configured with  ASP.NET 2.0 .NET Framework 3.5
to  ASP.NET 4.0 .NET Framework 4.

Here is how I did it.

My old setup:

Windows Server 2008 R2
IIS 7.5
ASP.NET
Application Pool : .NET Framework v2.0.50727
.NET Framework installed:  3.5 SP1

My new setup:

Windows Server 2008 R2
IIS 7.5
ASP.NET
Application Pool : .NET Framework v4.0.30319
.NET Framework installed:  4.0

The good thing is that the ASP.NET is backward compatible. You shoud publish the website on the new setup and it should work straight away.

In my case I had to remove these from web.config:


<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication"></section>
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="Everywhere"></section><section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication"></section><section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication"></section><section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication"></section>

If it still gives you problems got to IIS Manager and click Error Pages:

Select 500 , right click and select Edit Feature Settings

Here select “Detailed errors”

Now you should get detailed error within your web.config. Also check Event Viewer under the section Administrative Events

Written by arturito

January 25th, 2012 at 10:20 am

How to configure library mode in XBMC Apple TV 2G ( movie covers, title, genre) Part 2

with 4 comments


Now highlight library and press and hold Menu button.


Click button Left and highlight Library Mode

To get the xbmc to create the library properly always put the movie in the directory with the name and the year of the movie.
Let’s say you have file Armyofdarkness.avi. Stick it to the folder called Army of Darkness (1992)
as it appears in imdb.com http://www.imdb.com/title/tt0106308/

Let’s say xbmc didn’t get the movie right. No problem. Look at this case. The movie here is a The Dark City 1998 but the XBMC detected it as The Director’s Cut as the folder is called The Dark City – The Director’s Cut (1998)

We can fix it quickly:

In the next post I will show how to configure TV Shows and Music library

Written by arturito

December 3rd, 2011 at 8:11 pm

Posted in Apple TV 2,XBMC

How to configure library mode in XBMC Apple TV 2G ( movie covers, title, genre) Part 1

without comments

So you got yourself XBMC installed and you would like to get the XBMC to automatically download movie and tv shows covers, casts, synopis and rating. Like on the image below:

Well, XBMC has something that is called Library Mode which I will show how to configure.

What we need to do is:

1. Add shared directory with movies (local or remote). If you haven’t done it yet check this tutorial:
http://arturito.net/2011/10/20/how-to-add-network-drive-nas-storage-or-windows-share-in-xbmc/

2. Install IMDB scrapper.
*IMDB scrapper is a plugin that will download movie information and cover from imdb.com

3. Set content

Let’s install the scrapper:

Now with the scrapper installed we can start setting up content.

Continue to part 2

http://arturito.net/2011/12/03/how-to-configure-library-mode-in-xbmc-apple-tv-2g-movie-covers-title-genre-part-2/

 

Written by arturito

December 3rd, 2011 at 7:22 pm

Posted in Apple TV 2,XBMC

Tagged with ,

How to Find firmware version of Apple TV 2G (software and system version)

with one comment





In this article I will explain versions of Apple TV as it comes very confusing to some users.

The Apple TV device runs the operating system called iOS.
On this operating system runs Apple TV software system.

Imagine that it is like Microsoft Windows running Windows Media Player.

That’s why Apple TV 2G comes with two “version” numbers.

Software Version – which is also called firmware version.
We can find it under Settings > General > About  and see “Software Version”

System Version – which is the version of iOS.
We can find it under Settings > General > About by clicking once on “Software Version”

For example Apple TV Software Version 4.2 runs on iOS version 4.3




Written by arturito

November 30th, 2011 at 11:12 am

Posted in Apple TV 2

ASP.NET MVC2 Visual Studio Error – The project type is not supported by this installation

without comments




If you get this error when opening a solution in Visual Studio, just go to the project file (YourProject.csproj) which fails to open and change the line

<ProjectTypeGuids>{Some_GUID}</ProjectTypeGuids>

to

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>



Written by arturito

November 16th, 2011 at 8:03 am

ASP.NET MVC2 in the web farm – slow page load with high traffic – where is the bottleneck?

with one comment

Recently I have implemented quite complex e-commerce web application using technologies such as: ASP.NET MVC2, Linq2SQL , .NET 3.5 , SQL Server 2008 R2.

We have the whole thing hosted in the web farm.

We have 4 x IIS7 + 1 SQL SERVER 2008 load balanced with MS NLB

Static content is cached by external cache provider – Akamai, which reduces 86% of the requests.

Each web server has 32 GB of RAM and 4 x quad core CPUs so there are 64 cores on the front-end.

We store session state in tables of SQL server.

It works prefectly with medium traffic (page load = 0.2 -0.3 s)

but the company does the tv ads and during those ads the traffic hits up to 20,000 -30,000 users within 20-30 seconds.

In this moment the page slows down to 39 seconds. However, the usage of CPU’s and the memory doesn’t even arrive to 40% on any machine.

The bandwidth of the data centre does not arrive to the half of its limits.

Pages which are slow generate data from simple SELECTs of maximum 10 records from 1-2 tables only.

I gone through all possible things: I already had my queries compiled but I also optimized selects, created additional indexes studied a lot the problems of storing session in tables that sql server 2005 had (temdb) and I couldn’t figure out what was going on.

You could reproduce the the problem by launching stress tools against the web. The worst thing was that we could freeze the web just by launching stress tools from only two pc’s located in our offices.

I have also posted the question on stackoverflow
http://stackoverflow.com/questions/7644339/asp-net-mvc2-in-the-web-farm-slow-page-load-with-high-traffic
where people suggested to check indexes and use CompiledQuery.

In practice 90% of the bottlenecks are caused by database. After the whole week of tests and studying the problem I have possibly found a bug in the ASP.NET MVC2 library.
It was incredible how silly the thing was:

Let’s have a look at this code:


public ActionResult Index(){
var model = new SomeModel();
// Get data
....
return View(model);
}

In this code the View is generated using file Index.aspx.
However, this View needs to be found in some way and I guess the search of the this View is causing the problem.

Unbelievable but true – adding the name of the View removed the problem:


public ActionResult Index() {
 var model = new SomeModel();
// Get data
....
return View("Index",model);
}

I say it again, this problem does exists only when the web has a high number of users.
The MVC version I’m using is

Version: 2.0.0.0
Runtime: v2.0.50727

I have contacted the geeks responsible for the design and development of this great library to see what they say.

By all means I don’t  want to discourage anyone to use this library as it is absolutely fantastic and I use it a lot and I will carry on using it.

 

 

 

Written by arturito

October 24th, 2011 at 10:59 am

How to remove Server, X-AspNet-Version, X-AspNetMvc-Version and X-Powered-By from the response header in IIS7

without comments

You can check your response headers by using Firebug add-on for Firefox or just hit Ctrl+J in Chrome.

Unwanted info:

Server Microsoft-IIS/7.5
X-AspNetMvc-Version 3.0
X-AspNet-Version 4.0.303319
X-Powered-By ASP.NET

 

1. Removing X-AspNet-Version

In web.config stick this line in


<system.web>
      <httpRuntime enableVersionHeader="false"/>
	...

2. Removing X-AspNetMvc-Version

In Global.asax.cs add this line:


protected void Application_Start()
{
    MvcHandler.DisableMvcResponseHeader = true;
}

3. Removing or changing Server

Add this module class to your project.


using System;
using System.Web;

namespace Project.Infrastructure.Web.Modules.Http
{
    public class CustomHeaderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += OnPreSendRequestHeaders;
        }

        public void Dispose() { }

        void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
	     //HttpContext.Current.Response.Headers.Remove("Server");
            // Or you can set something funny
	    HttpContext.Current.Response.Headers.Set("Server", "CERN httpd");
        }
    }
}

And add set it in web config


	<system.webServer>
		<modules>
        <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule" />

4. Removing or changing X-Powered-By

Go to IIS7 Management Console and open HTTP Response Headers

And that should be it!

 

Written by arturito

October 21st, 2011 at 7:07 am

How to add network drive (NAS storage) or windows share in XBMC

without comments

 
Please specify drive hostname or ip address of the device and the name of the hared folder.
Depending on your security settings you might also provide username and password.

(My network storage is Synology DS110j
http://www.synology.com/us/products/DS110j/index.php)

 

Written by arturito

October 20th, 2011 at 6:35 am

Posted in Apple TV 2,XBMC

InstallSqlState.sql errors: ASPState_Job_DeleteExpiredSessions does not exist and The specified @name (‘[Uncategorized (Local)]‘) already exists

without comments

So........... you are configuring ASP.NET SQL session state and Microsoft's
documentation tells you to execute InstallSqlState.sql found in
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
but you always get this:

If the job does not exist, an error from msdb.dbo.sp_delete_job is expected.
Msg 14262, Level 16, State 1, Procedure sp_verify_job_identifiers, Line 67
The specified @job_name ('ASPState_Job_DeleteExpiredSessions') does not exist.
If the category already exists, an error from msdb.dbo.sp_add_category is expected.
Msg 14261, Level 16, State 1, Procedure sp_add_category, Line 32
The specified @name ('[Uncategorized (Local)]') already exists.
Well then..... you are doing it wrong. Open command line (Start->Run-> cmd)

1.cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
2) Execute:

aspnet_regsql.exe –ssadd -U <username> -P <passowrd> -S <servername>

For example

aspnet_regsql.exe –ssadd -U webuser -P d4rk!s1de -S mssql.arturito.net You can also do 

aspnet_regsql.exe –ssadd -E -S mssql.arturito.net - if you use Windows authentication

b) aspnet_regsql.exe –ssadd -U <username> -P <passowrd> -S <servername>for exampleb) aspnet_regsql.exe –ssadd -U webuser -P d4rk!s1de -S mssql.arturito.net

Written by arturito

September 19th, 2011 at 11:59 am

Posted in ASP.NET MVC2,IIS7

How to Switch Between HTTP and HTTPS in ASP.NET MVC2 And Allow AJAX Requests From Site Master.

without comments

In order to serve the request throught SSL in ASP.NET MVC2 we can simple use Action attribute [RequireHttps]:

		//LoginController
        [RequireHttps]
        public ActionResult Index()
        {
            return View();
        }

Let’s say I served a login form here. Then the user logs in.

		//LoginController
        [RequireHttps]
        [HttpPost]
        public ActionResult Index(LoginModel model)
        {
            if (model != null && model.Username == "arturito")
                 return RedirectToAction("List", "Home");
            else
                return RedirectToAction("Login");
        }

Note that the redirection ( RedirectToAction(“List”, “Home”) ) is taking us to HomeController List action.
However the action List in HomeController is not decorated in [RequireHttps] so it should return to HTTP.

        //HomeController
		public ActionResult List()
        {
            return View();
        }

BUT IT DOESN’T!
You will remain in HTTPS.

Jeff Widmer worked out a great solution and posted it in his article.
In his solution we have BaseController and we are overriding OnAuthorization method

    public class BaseController : Controller
    {
            protected override void OnAuthorization(AuthorizationContext filterContext)
            {

                //the RequireHttpsAttribute set on the Controller Action will handle redirecting to Https.
                // We just need to handle any requests that are already under SSL but should not be.
                if (Request.IsSecureConnection)
                {
                    Boolean requireHttps = false;
                    requireHttps = filterContext.ActionDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute), false).Count() >= 1;

                    //If this request is under ssl but yet the controller action
                    // does not require it, then redirect to the http version.
                    if (!requireHttps && !filterContext.IsChildAction)
                    {
                        UriBuilder uriBuilder = new UriBuilder(Request.Url);

                        //change the scheme
                        uriBuilder.Scheme = "http";
                        uriBuilder.Port = 80;

                        filterContext.Result = this.Redirect(uriBuilder.Uri.AbsoluteUri);
                    }
                }

                base.OnAuthorization(filterContext);
            }

    }

But there is one problem left!

Let’s say that all pages served through HTTP and HTTPS use the same site master page which contains a link or the form that creates ajax request.
As an example let’s look at this simple action:

		// Home Controller
        [HttpPost]
        public ActionResult Ajax()
        {
            return Content("This is Ajax");
        }

This works great from HTTP page!

How to Switch Between HTTP and HTTPS in ASP.NET MVC2 And Allow AJAX Requests From Site Master.

How to Switch Between HTTP and HTTPS in ASP.NET MVC2 And Allow AJAX Requests From Site Master.

….but when we call the same action from HTTPS page it doesn’t work!
How to Switch Between HTTP and HTTPS in ASP.NET MVC2 And Allow AJAX Requests From Site Master.

Why? This is called crossdomain ajax request, which by default is not allowed for security reasons. There are some methods/libraries/proxies to achieve this but it is not very common yet.

If we decorate it with [RequireHttps] attribute:

		// Home Controller
		[RequireHttps]
        [HttpPost]
        public ActionResult Ajax()
        {
            return Content("This is Ajax");
        }

This action becomes available only if requested from the page served through HTTPS. We can no longer call it from the page served through http.

Well then, let’s allow to perform all ajax request from pages served by both HTTP and HTTPS:

protected override void OnAuthorization(AuthorizationContext filterContext)
            {

                //the RequireHttpsAttribute set on the Controller Action will handle redirecting to Https.
                // We just need to handle any requests that are already under SSL but should not be.
                if (Request.IsSecureConnection)
                {
                    Boolean requireHttps = false;
                    requireHttps = filterContext.ActionDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute), false).Count() >= 1;

                    // Allow Ajax request from both http and https pages
                    if (Request.IsAjaxRequest())
                    {
                        base.OnAuthorization(filterContext);
                        return;
                    }

                    //If this request is under ssl but yet the controller action
                    // does not require it, then redirect to the http version.
                    if (!requireHttps && !filterContext.IsChildAction)
                    {
                        UriBuilder uriBuilder = new UriBuilder(Request.Url);

                        //change the scheme
                        uriBuilder.Scheme = "http";
                        uriBuilder.Port = 80;

                        filterContext.Result = this.Redirect(uriBuilder.Uri.AbsoluteUri);
                    }
                }

                base.OnAuthorization(filterContext);
            }

    }

Now whether we are on login page (HTTPS) or any other page (HTTP) we can create ajax requests in the site master without decorating ajax actions with additional attributes or messing around
with url scheme in the Views.

Here is a downloadable example:  http://www.mediafire.com/?0d6dn6w489yalgo

GL

Written by arturito

August 5th, 2011 at 4:12 pm