Archive

Archive for April, 2012

.NET Stack Trace

April 19, 2012 Leave a comment

To get the current Stack Trace, use the following function

var s = new System.Diagnostics.StackTrace();

And to access the stack frames, look at the GetFrames() function

 

Finally if you need to know what is the current class and function name, you can use

var theMethod = s.GetFrames().First().GetMethod();

var theClassDotMethod = theMethod.ReflectedType + "." + theMethod.Name

Advertisements
Categories: ASP.NET

System Centre 2012 Prerequisites

April 12, 2012 Leave a comment

Below is the list of all the prerequisites for System Centre 2012 along with the steps on how to get the required files

Microsoft.NET Framework 4 Extended

  • Just click on the download link

Microsoft Report Viewer Redistributable 2008

  • Click on the download link, you will need to put it in a separate folder from the next item since both have the same filename

Microsoft Report Viewer Redistributable 2010

  • Click on the download link, you will need to put it in a separate folder from the above item since both have the same filename

Microsoft SQL Server 2008 R2

  • All the files in whichever version of SQL 2008 R2 you are using (typically all files in the iso)
  • image

Microsoft SQL Server 2008 R2 Native Client

  • Just click on the download link

Windows Automated Installation Kit

  • Just click on the download link

Microsoft SQL Server 2008 R2 Analysis Management Objects

  • Just click on the download link

Microsoft SQL Server 2008 R2 Command Line Utilities

  • Just click on the download link

Microsoft SQL Server 2008 R2 Service Pack 1

  • Click on the download link
  • Extract all the files into a folder, point to the folder

Microsoft SQL Server 2008 R2 Cumulative Update 4

  • Click on the download link to request for the actual links to be emailed to you
  • It is the one which is about 350MB
  • Once you download the file (441824_intl_x64_zip), unzip it to extract out the executable file
  • Extract the file (SQLServer2008R2-KB2633146-x64.exe) in the executable file into another folder
  • Point to this folder
Categories: System Centre 2012

System Centre 2012 Unified Installer : Fix for The WinRM settings are not configured correctly

April 12, 2012 4 comments

 

When installing System Centre 2012 Unified Installer on a Windows 2008 R2 machine, you might encounter the following error

image

 

To fix this, first ensure that your administrator account has a password.

Next fire up a command prompt with Administrator rights and run the following commands

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f

>reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
The operation completed successfully.

winrm qc -q

>winrm qc -q
WinRM is not set up to receive requests on this machine.
The following changes must be made:

Start the WinRM service.

WinRM has been updated to receive requests.

WinRM service started.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
machine.
Enable the WinRM firewall exception.

WinRM has been updated for remote management.

Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
machine.
WinRM firewall exception enabled.

 

winrm set winrm/config/service/auth @{CredSSP="True"}

>winrm set winrm/config/service/auth @{CredSSP="True"}
Auth
    Basic = false
    Kerberos = true
    Negotiate = true
    Certificate = false
    CredSSP = true
    CbtHardeningLevel = Relaxed

winrm set winrm/config/winrs @{AllowRemoteShellAccess="True"}

>winrm set winrm/config/winrs @{AllowRemoteShellAccess="True"}
Winrs
    AllowRemoteShellAccess = true
    IdleTimeout = 180000
    MaxConcurrentUsers = 5
    MaxShellRunTime = 2147483647
    MaxProcessesPerShell = 15
    MaxMemoryPerShellMB = 150
    MaxShellsPerUser = 5

winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"}

>winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"}
Winrs
    AllowRemoteShellAccess = true
    IdleTimeout = 180000
    MaxConcurrentUsers = 5
    MaxShellRunTime = 2147483647
    MaxProcessesPerShell = 15
    MaxMemoryPerShellMB = 2048
    MaxShellsPerUser = 5

winrm set winrm/config/client @{TrustedHosts="*"}

>winrm set winrm/config/client @{TrustedHosts="*"}

Client
    NetworkDelayms = 5000
    URLPrefix = wsman
    AllowUnencrypted = false
    Auth
        Basic = true
        Digest = true
        Kerberos = true
        Negotiate = true
        Certificate = true
        CredSSP = false
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    TrustedHosts = *

winrm set winrm/config/client/auth @{CredSSP="True"}

>winrm set winrm/config/client/auth @{CredSSP="True"}
Auth
    Basic = true
    Digest = true
    Kerberos = true
    Negotiate = true
    Certificate = true
    CredSSP = true

 

You can now try installing System Centre 2012 again.

Getting ASP.NET MVC 3 to work with ASP.NET Website project

April 10, 2012 13 comments

There are numerous blog posts on how to get MVC to work with ASP.NET Web Applications. However there are still scenarios where developers are using normal ASP.NET website projects rather than Web Application projects.

Below are the steps to enable MVC 3 with an asp.net website project

1. Install ASP.NET MVC 3

2. Modify web.config

Open up web.config in Visual Studio and add the following lines inside the <compilation><assemblies> section

<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

3. Modify global.asax

Next you will need to add in the code for MVC triggers inside global.asax (create one if it does not exist)

Add the following lines after <%@ Application Language="C#" %>

<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="System.Web.Routing" %>

Add the following after <script runat="server">

public void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute("Home",
"home/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });}

add the following inside application_start

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);

At this point, your global.asax should look like
image

4. Creating the controller

Because this is a website project, compilation is at runtime, so you will have to create your controllers inside the App_Code folder rather than the normal Controller folder in the main site

Note that your controller class needs to end with the Controller keyword. In the example, with a controller = “Home”, the classname for the controller needs to be HomeController

To add your first controller, right click on the App_Code folder and create a new class with the file name as HomeController.cs

Paste the following code into the HomeController.cs (replace everything)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

public partial class HomeController : Controller
{
    protected override void Execute(System.Web.Routing.RequestContext requestContext)
    {
        base.Execute(requestContext);
    }

    public ActionResult Index()
    {
        var r = new ContentResult();
        r.Content = "Hello World";
        return r;
    }
}

 

5. Test the site

Now that you have generated the routing and created the controller, browse to localhost/home. You should see “Hello World”

image

Categories: ASP.NET, IIS, MVC