ASP .NET MVC Model Binding

Model binder takes the values coming from an HTML page and maps them to a corresponding model.

The Model binder is capable of retrieving the data from HTML form variables, POSTed variables and files, query string parameters and the values added in the routes.

The DefaultModelBinder class magically does all the type conversion and mapping of all values to the Model properties.

The id of the HTML input fields must be same as the Property names of the Model. The mapping will be based on the Property name by default.  HTML helper methods are very helpful here because these helper methods will generate the HTML proper IDs for the Model.

 

SignalR 1.1.3

Get SignalR version 1.1.3 library by NuGet

install-package Microsoft.AspNet.SignalR -Version 1.1.3

Register your hubs in global.asax before registering routes

protected void Application_Start()
{
     RouteTable.Routes.MapHubs();
     ...
     RouteConfig.RegisterRoutes(RouteTable.Routes);
}

Could not load type ‘System.ServiceModel.Activation.HttpModule’

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Description: An unhandled exception occurred during the execution of the current Web request. Review the stack trace for more information about the error and where it originated in the code.
 Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Taki błąd pojawia się jeśli instalujemy IIS i .NET Framework w odwróconej kolejności, a mianowicie wtedy, kiedy IIS jest instalowany po zainstalowaniu .NET Framework, albo jeśli WCF Http Activation moduł jest instalowany po zainstalowaniu IIS i .NET Framework.
Problem ten można rozwiązać za pomocą ASP.NET IIS Registration Tool (aspnet_regiis.exe) .
Należy uruchomić to polecenie z parametrami -iru:

aspnet_regiis.exe -iru

Dodatkowo przydatne może okazać się również poniższe polecenie:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>ServiceModelReg.exe -r

Elmah

Automatyczne logowanie nieprzechwyconych wyjątków do bazy MS-SQL za pomocą biblioteki Elmah

Przykładowy web.config

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <configSections>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        </sectionGroup>
    </configSections>
    <elmah>
        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" />
        <security allowRemoteAccess="0" />
    </elmah>
    <connectionStrings>        
        <add name="elmah" connectionString="Data Source=G-PC\SQLEXPRESS;Initial Catalog=BAppt;User Id=User;Password=Passwd;" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="Elmah, Version=1.0.10617.0, Culture=neutral, PublicKeyToken=null"/>
            </assemblies>
        </compilation>
        <authentication mode="Forms">
            <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
        </authentication>
        <membership>
            <providers>
                <clear/>
                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
            </providers>
        </membership>
        <profile>
            <providers>
                <clear/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear/>
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
            </providers>
        </roleManager>
        <globalization uiCulture="pl" culture="pl-PL"/>
        <customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx">
            <error statusCode="404" redirect="~/errors/PageNotFound.aspx" />
        </customErrors>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        </modules>
        <handlers>
            <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
        </handlers>
    </system.webServer>
</configuration>