-
Notifications
You must be signed in to change notification settings - Fork 4
Hello World
paulcamp edited this page May 3, 2019
·
2 revisions
Refer to the example AspNet application
for a fully working example web application.
Build the project, then within IIS manager, add a new website, set the physical path to the project folder (the folder containing web.config) and browse the website.
You should see something like this:
Hello world
My type is: Areas.Example.Example.Index_cshtml
My base type is: MustardBlack.Example.Areas.Example.Example.NewRazorViewPage
I'm an anchor with a funny title attribute
I'm raw H2 HTML
<b>I'm html encoded</b>
I'm inside a partial
I'm inside a section
However, if you prefer building your own Hello World application step by step then:
Using VS 2007, create a new project ->
Visual C# -> Class Library (.NET Framework 4.7.1)
Name the project MustardBlack.Example
Add the following packages:
- "MustardBlack"
- "MustardBlack.Hosting.AspNet"
- "MustardBlack.ViewEngines.Razor"
- "NanoIOC"
- Replace the code in your entry point class (defaults to
class1.cs
) with this:
using System;
using MustardBlack.Applications;
using MustardBlack.Handlers;
using MustardBlack.Hosting;
using MustardBlack.Results;
using MustardBlack.Routing;
using NanoIoC;
namespace MustardBlack.Example
{
sealed class ExampleApplication : ApplicationBase
{
public ExampleApplication(IContainer container) : base(container)
{
}
public override Type DefaultErrorHandler => null;
public override bool CanServe(IRequest request)
{
return true;
}
protected override void Configure()
{
this.RegisterArea<ExampleAreaRegistration>();
this.RegisterPipelineOperator<RoutingPipelineOperator>();
this.RegisterPipelineOperator<HandlerExecutorPipelineOperator>();
this.RegisterPipelineOperator<ErrorHandlingPipelineOperator>();
this.RegisterPipelineOperator<ResultExecutorPipelineOperator>();
}
}
}
- Replace
app.config
withweb.config
and use the following content:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<authentication mode="None" />
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.7.1" />
<httpRuntime targetFramework="4.7.1" requestPathInvalidCharacters="" requestValidationMode="2.0" enableVersionHeader="false" maxUrlLength="10240" maxRequestLength="20480" relaxedUrlToFileSystemMapping="true" />
<sessionState mode="Off" />
<globalization culture="auto:en" uiCulture="auto:en" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="UrlRoutingModule-4.0"/>
<remove name="OutputCache"/>
<add name="BootstrapModule" type="MustardBlack.Hosting.AspNet.BootstrapModule, MustardBlack.Hosting.AspNet" />
<add name="HeaderCloakingModule" type="MustardBlack.Hosting.AspNet.HeaderCloakingModule, MustardBlack.Hosting.AspNet" />
<add name="CompressionModule" type="MustardBlack.Hosting.AspNet.CompressionModule, MustardBlack.Hosting.AspNet" />
</modules>
<handlers>
<add name="RequestHandler" type="MustardBlack.Hosting.AspNet.RequestHandler, MustardBlack.Hosting.AspNet" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
</handlers>
<urlCompression doStaticCompression="false" doDynamicCompression="false" />
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20971520" />
</requestFiltering>
</security>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.codedom>
<compilers>
<compiler
language="c#;cs;csharp"
extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
warningLevel="4"
compilerOptions="/langversion:7 /nowarn:1659;1699;1701" />
</compilers>
</system.codedom>
<system.web.webPages.razor>
<!-- This is only a hint to help IntelliSense -->
<pages pageBaseType="MustardBlack.ViewEngines.Razor.RazorViewPage">
<namespaces>
<!-- These are actually used -->
<add namespace="System"/>
<add namespace="System.Net"/>
</namespaces>
<taghelpers>
<add type="MustardBlack.Example.Areas.Example.Example.ScriptTagHelper, MustardBlack.Example" />
</taghelpers>
</pages>
</system.web.webPages.razor>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.3.0" newVersion="1.4.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.3.0" newVersion="1.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.3.0" newVersion="1.4.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Composition.AttributedModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.31.0" newVersion="1.0.33.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
-
In VS2007 solution view, Create the folders:
Areas/Example
Cfg
-
Copy the folder content from the example repo and include it in your project.
-
Build the project
-
Point IIS to the phyical folder and go !
TODO