Tuesday, March 24, 2009

Using the ActiveReports WebViewer with ASP.NET MVC 1.0

The ActiveReports WebViewer was designed for ASP.NET WebForms, not for ViewPages in MVC. Therefore we still need a little bit of code-behind for the WebViewer to work. This can be accomplished by adding a WebForm to the Views folder and changing the code-behind class to inherit off of System.Web.Mvc.ViewPage instead System.Web.UI.Page.

Take a look at the screencast for detailed instructions on how to set up the default MVC template to work with the ActiveReports WebViewer control.







If you would like to download the sample created during the screencast you can grab it here.

EDIT: I know the video is kind of on the smaller side, therefore, I will be updating this post at a future time with a step by step guide (with images). Until then, bear with the screencast and have a look at the sample linked above.

Saturday, October 18, 2008

ASP.NET MVC Web Site Template

When I installed the ASP.NET MVC Beta, I was disappointed that it only included an ASP.NET Web Application template. Some developers could probably argue for hours over which is better, the Web Application template or Web Site template, but this is more of a personal preference, therefore I won’t be going over the pros and cons of those project types here.

I wanted a Web Site template for ASP.NET MVC, and here I’ll explain how I created it.

The first, and most obvious step, is to install the ASP.NET MVC Beta. Once that’s installed, fire up Visual Studio 2008 and create a new Web Site. Once the project is up and running, add references to the following assemblies:

System.Web.AbstractionsSystem.Web.MvcSystem.Web.Routing
In the default install of the MVC Beta, these assembles are all found in %ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC Beta\Assemblies.

Now it’s time to make modifications to the Web.config to add the HTTP Modules, Handlers, and namespaces for each WebForm/ViewPage.

Under the system.web\pages section of the Web.config, add a node called namespaces and then add the following namespaces:

System.Web.MvcSystem.Web.Mvc.AjaxSystem.Web.Mvc.HtmlSystem.Web.Routing
The XML should look like this:

<!-- ... -->
<namespaces>
<add namespace="System.Web.Mvc">
<add namespace="System.Web.Mvc.Ajax">
<add namespace="System.Web.Mvc.Html">
<add namespace="System.Web.Routing">
</add>
<!-- ... -->


In the section below pages, (it should be httpHandlers), we need to add an entry for the MvcHttpHandler.

<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


Then add the UrlRoutingModule to the httpModules configuration section.

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


If you plan on deploying to IIS 7.0, then we need to make a few changes to the system.webServer section. Under modules, add the following:

<remove name="UrlRoutingModule">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


In handlers, add this:

<remove name="MvcHttpHandler">
<add name="MvcHttpHandler" precondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<remove name="UrlRoutingHandler">
<add name="UrlRoutingHandler" precondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">



Now we can move on to setting up the project template files. First, add a Global application class (Global.asax). Clear its content below the Application tag. Then make the Global.asax inherit from a class called MvcApplication. (This class doesn’t exist yet, but we will create it soon).

<%@ Application Language="C#" Inherits="MvcApplication" %>


To create the MvcApplication, add a new class file to the App_Code folder. If App_Code doesn’t exist, create it by right-clicking on your project in the Solution Explorer and selecting App_Code from the Add ASP.NET Folder submenu.

The MvcApplication class needs to inherit from HttpApplication. The goal of this class is to register the default route for the default MVC view. Be sure to add the System.Web.Routing namespace to the top of this class file.

using System;
using System.Web;
using System.Web.Routing;
using System.Web.Mvc;

public class MvcApplication : HttpApplication
{
static void Application_Start()
{
// do not route requests for web resources
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// add the default route
RouteTable.Routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Default", action = "Index", id = "" }
);
}
}


Now that we have the MvcApplication set up, we need to set up the Default web form so it routes requests to the MvcHttpHandler. Here’s the code:

using System;
using System.Web;
using System.Web.Mvc;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.RewritePath(Request.ApplicationPath);
IHttpHandler handler = new MvcHttpHandler();
handler.ProcessRequest(HttpContext.Current);
}
}


Now, create two folders within App_Code called Controllers and Models. Then create a folder in your web site’s root called Views. Within the Views folder add a subfolder called Default. In the Controllers folder, create a class file called DefaultController. The source for DefaultController is below:

using System;
using System.Web.Mvc;

[HandleError]
public class DefaultController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";

return View();
}
}


This template isn’t going to use Models, that’s for future use though. So let’s skip ahead to adding the default view. In the Views\Default directory add a new Web Form called Index.aspx. Yes, I said Web Form because the ASP.NET MVC Beta also does not include the ViewPage item template for Web Site projects. So the first order of business is to change the codebehind to have the Index view inherit from System.Web.Mvc.ViewPage rather than from System.Web.UI.Page.

public partial class Views_Default_Index : System.Web.Mvc.ViewPage
{
}


Now, go to the Index ViewPage’s markup and add the following line to the body between the div tags:

<%= Html.Encode(ViewData["Message"]) %>


At this point the project can be compiled and debugged. You should see your message (set in the controller) in your default browser.

To save the template, select Export Template from the File menu and follow the steps in the wizard.

Friday, August 1, 2008

Manicotti

Well, I guess it paid off, general consensus was everyone liked it.

BUT... It was just another reminder of why I hate cooking things like Manicotti. What made it take even more time was instead of preparing it for 4 people, I made enough to feed 12 normal people (in this case 8 normal people and 1 TimP).

I even had to run back to the store halfway through because a good amount of shells were splitting during the boiling process.


So 3 hours after prepping it last night, and 35 mins in the oven this morning... everybody in the office was happy.

Just don't expect this type of cooking from me often :)

...it really is a pain in the ass.


I enjoy cooking on the grill much much much more than the process of making Manicotti.

</rant>

Wednesday, July 16, 2008

Project Euler

A co-worker who does not blog (at least not that I know of) introduced us to Project Euler today. It's a web site which lists various math problems which are to be solved using simple programs.

Well, that may sound dull, it's quite the opposite. For those who may have neglected their math skills a little bit while stuck in the realm of UI design, this is a cool way to build those problem solving skills.

At our office, we're planning on doing weekly meetings after the work day to go over the problems and compare our solutions.

Now, although these problems deal with large numbers, you shouldn't be sitting in front of your computer for hours waiting for a result. Each problem was designed to be solved by a computer in a minute or less. If you're waiting on your program to finish... you're doing it wrong.

Check it out!

Also, sign up for an account in order to submit your results for verification. Once you do that for a particular problem, you get access to a PDF document which explains the problem in more detail and access to the forums for that particular problem to discuss with others who have been solving these problems.

Wednesday, March 26, 2008

What a day...

This morning I got hit with a "Seatbelt ticket"... grrr.

Then I received my additional 2gb of RAM for my home system... sweet.

Then I somehow ended up with a shard of glass in my big toe... grrr.

Then I played around with server 2008 and discovered a pretty cool new feature in Terminal Services: Remote Apps. So basically, I have TS set up on my Server 08 VM, and added the InetMgr as a RemoteApp just to test this out with. So on my XP box, I have a remote window that has the Vista theme, neat...

Wednesday, February 13, 2008

My cities are named after alcohol...

Amaretto



Amaretto is a mid-sized desert city which thrives on tourism. It's romantic atmostphere, low CO2 footprint, almost non-existent crime, and the various venues keep my Sims happy. I also built a campus area so my Sims can be smart.

Parrot Bay




Parrot Bay is a tropical metropolis. This was my first city, and my poor planning led to tearing down the homes of multiple Sims to build skyrise apartments for my booming population. I made some bad decisions when it came to choosing power sources and businesses, pollution was terrible, but this has since been resolved when nuclear power was used as a cleaner alternative. This capitalist city has a lot of venues (bars, liquor stores, etc) which promote crime, so that is somewhat of an issue. Also, Parrot Bay's Liberal Arts College led to a large population of hippies moving in. They make city life less fun for the other Sims by protesting, and lingering in venues all day, preventing other Sims from blowing off steam.

As with all capitalist cities, we have a very nice neighborhood (near) with large houses, and for some reason, all the Sims in this neighborhood seem to be driving Lamborghinis of various colors. Opposite to this portion of town, on the other side of the downtown area exists low cost housing, and government sponsored projects. The less fortunate Sims also contribute to Parrot Bay's crime problem.



So this is one of my hobbies outside of my fooling around with my computers, playing around with Mono, and my various other geek related activities. This, by the way, is SimCity Societies... and yes, it's addictive to build my societies :)

Wednesday, January 30, 2008

The mac is awesome...

OK, so I'm not sure if it's fair to say this MacBook is downright probably the best system I've ever had... (after 1 week). But I think it's true. First of all, the hardware is downright awesome (this notebook will build large projects rather quickly (in comparison to my desktops I use to build source (which are pretty high end)), it also plays Team Fortress 2 better than my home desktop). Secondly, I can dual-boot into Windows XP (screw Vista) and can do all my dev/support/screencast/etc job functions in either OS (OS X or Win XP) thanks to Parallels Desktop and my Boot Camp partition.

If you are considering getting a new laptop any time soon, I'd say get a Mac. Yes, there is a price difference, but it's well worth it. (If you look, you can find refurb MacBook Pros for around $1,700).

I still can't get over some of the cool features on this damn thing. That Dashboard app is awesome.