ServiceStack Razor allows you to create HTML views for your services using Razor syntax. By default, ServiceStack looks for views in the /Views folder in your project.
To create a default page for your ServiceStack Razor application, follow these steps:
/Views folder called _Layout.cshtml. This file will define the layout of your HTML pages.<!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> </head> <body> @RenderBody() </body> </html>
/Views folder called default.cshtml. This file will define the content of your default page.@inherits ViewPage<object> @section Title { Default Page } <h1>Welcome to my ServiceStack Razor application!</h1> AppHost.cs file and add the following code to the Configure() method to register the ServiceStack Razor plugin and specify the default page:Plugins.Add(new RazorFormat()); SetConfig(new HostConfig { DefaultRedirectPath = "/default.cshtml" }); In this example, we're registering the RazorFormat plugin and specifying /default.cshtml as the default redirect path.
http://localhost:1234/) to see your default page.Note that the default page will be shown whenever a request is made to the root URL of your ServiceStack application. If you want to specify a different default page for a particular service, you can do so by using the IReturn interface and setting the DefaultView property.
"ServiceStack Razor default page configuration"
// Inside your AppHost.cs SetConfig(new HostConfig { DefaultRedirectPath = "/default" }); "ServiceStack Razor default page with attribute"
[DefaultPage] attribute to specify the default Razor page for a ServiceStack service.// Inside your service class [DefaultPage("/default")] public class MyService : Service { // Service logic } "ServiceStack Razor default page with custom route"
// Inside your AppHost.cs Routes.Add<DefaultPage>("/default"); "ServiceStack Razor default page and route conventions"
// Inside your AppHost.cs Routes.Add<DefaultPage>("/{Path*}"); "ServiceStack Razor default page with custom HTML"
// Inside your AppHost.cs SetConfig(new HostConfig { DefaultRedirectPath = "/default", GlobalResponseHeaders = { { "Content-Type", "text/html" } } }); "ServiceStack Razor default page redirect"
// Inside your AppHost.cs SetConfig(new HostConfig { DefaultRedirectPath = "/redirect" }); "ServiceStack Razor default page with layout"
// Inside your AppHost.cs SetConfig(new HostConfig { DefaultRedirectPath = "/default", RazorDefaultPageName = "Default", RazorDefaultPageBody = "<h1>Hello, World!</h1>" }); "ServiceStack Razor default page per content type"
// Inside your AppHost.cs SetConfig(new HostConfig { DefaultContentType = MimeTypes.Json }); Routes.Add<DefaultJsonPage>("/default.json"); "ServiceStack Razor default page with custom route handler"
// Inside your AppHost.cs Routes.Add<DefaultPage>("/default", new RazorHandler("/custom/default.cshtml")); "ServiceStack Razor default page and template resolution"
// Inside your AppHost.cs Plugins.Add(new RazorFormat { UseCustomNamespaces = true, TemplateBaseType = typeof(CustomRazorBase) }); tvos spotfire temporary-files android-handler userid transition backcolor dispatch routeparams uifont