Skip to main content

Asp.NET Strict XHTML - Form Name Attribute

Generated XHTML by the .NET environment can throw an error if creating strict XHTML 1.1 as defined by


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">


The .NET environment adds the attribute "name" to the "Form" tag, which is not valid, strict XHTML 1.1 as shown in the screen shot below when validating against the W3C service.

Screen shot of W3C Strict XHTML 1.1 validation error

To remove this error, the .NET environment needs to be told to generate strict XHTML, as opposed to transitional XHTML or HTML or some other format.

This can be done by adding "<xhtmlConformance mode="Strict"/>" to the web.config file within the system.web node e.g.


<?xml version="1.0"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<xhtmlConformance mode="Strict"/>
</system.web>
</configuration>
Resources:
W3C validator: http://validator.w3.org/
MSDN: http://msdn.microsoft.com/en-us/library/ms228268.aspx

Comments

Popular posts from this blog

EF CodeFirst Database.SetInitializser Requires Connection to 'master' Database Error

One of the features of EF CodeFirst is the ability to automatically drop and recreate a database if the model changes or if the database does not exist, which is pretty useful when just doing development work. In a web app this is done in the Global.asax file within "protected void Application_Start()" as per this post from Scott Guthrie -  http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx . An example would be: protected void Application_Start() { Database.SetInitializer<yourdbcontex>(new DropCreateDatabaseIfModelChanges<yourdbcontext>()); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } However when using the Database.SetInitializer and trying to rebuild the database, the following exception may be encountered, especially if using SQL Server Express: "This operation requires a connection to the 'master'...

Enable .NET 8 Preview in Visual Studio

Download the SDK using Download .NET 8.0 (Linux, macOS, and Windows) (microsoft.com)  and install it. To enable projects to target the .NET 8 preview framework, the preview option in Visual Studio needs to be enabled, otherwise the option to target .NET 8 will not be available as shown below when setting up a new project (or trying to upgrade an existing one). To allow .NET 8 Preview to be used as a target framework for projects, the preview option needs to be enabled in Visual Studio. Open Visual Studio and select "Continue without code" In Visual Studio, select Tools then Options In Options, under Environment, select Preview Features and enable Use previews of the .NET SDK.

.NET 8 Blazor Server App _Host Routing Internal Server Error

 When firing up a new Blazor Server App with .NET 8 Preview, the following error was occurring.   An unhandled exception occurred while processing the request. InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area: }. Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DynamicPageEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates) To resolve, the project file can be updated with   References https://github.com/dotnet/aspnetcore/issues/36535#issuecomment-919861308 More info available on UseRazorSourceGenerator at  https://learn.microsoft.com/en-us/aspnet/core/razor-pages/sdk?view=aspnetcore-7.0