Hello team,
In my mvc C# inventory management application, my date dataType in the SQL server DB is date( yyyy-MM-dd), which I did data manipulation at the frontend to covert it to dd-MM-yyyy and it works on my local machine but when I hosted on somee it is not working as I want, but if use nvarchar dataType for the date format as string I got it perfectly as dd-MM-yyyy, I guess somee.com server is configured that way but my worry also is when I want to filter sales sales data wouldn't it cause any problems. Because our date format is dd-MM-yyyy, I did everything possible on the live server to covert it to dd-MM-yyyy but is not working. Kindly assist, thanks.
Prasad RaveendranPosted Jan 24, 2026, 2:36 AM
Storing dates as
nvarcharjust to control the format is the wrong fix. v KeepDATE / DATETIMEin the DB and control formatting in MVC.try this option in web.config
culture="en-GB"
uiCulture="en-GB" />
In addition to that, if users submit dates like
dd-MM-yyyy ,MVC must know how to parse it.[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime SaleDate { get; set; }
You need this only if:
Users enter or submit dates as
dd-MM-yyyyAnd MVC fails to bind it correctly on POST (null / wrong date / model error)
Emmmanuel FIADUFEPosted Jan 27, 2026, 1:09 AM
Okay thank you Mr Prasad Raveendran
I will check and revert please.
Raghunath BhukanPosted Jan 23, 2026, 4:19 PM
Hi Emmmanuel FIADUFE,
Yes, you need to apply the changes in your codebase and then republish the application.
You will not see the Global.asax.cs file in the published folder because it is a backend (code-behind) file. During publishing, it is compiled into a DLL and included in the application’s binaries.
When published, the code in
Global.asax.csbecomes part of an assembly (DLL), typically namedApp_global.asax.dll, which is placed in thebinfolder of your published application.Emmmanuel FIADUFEPosted Jan 23, 2026, 3:51 PM
Or should make the changes on my local machine and republish the application again since I can't find the Global.asax file you are referring to.
Emmmanuel FIADUFEPosted Jan 23, 2026, 3:45 PM
Pls on the somee server, I can only see one Global.asax file in my file manager directory, I open other folders such as bin and views but nothing like that is there except the one I was talking about, I'm saying this because you said I place the code at the wrong location.
Raghunath BhukanPosted Jan 23, 2026, 3:18 PM
What went wrong (very important)
You accidentally put C# code inside
Global.asax, which is a markup file, not a C# file.This line proves it:
And this part:
ASP.NET is trying to parse markup, but it finds raw C# code instead.
Correct structure (this matters):
You should have TWO separate files:
1.
Global.asax(markup file – VERY SMALL)This file should contain ONLY ONE LINE:
Do NOT put methods here
Do NOT put
{ }hereDo NOT put C# logic here
2.
Global.asax.cs(code-behind – C# logic goes here)This is where your method belongs.
Method is inside the class
Correct namespace
Correct file
No parser error
Why your current setup fails:
You effectively have this (invalid):
ASP.NET does not allow raw C# inside
.asaxmarkup.Quick checklist to fix it:
Open Global.asax
Leave only the directive line
Open Global.asax.cs
Put
Application_BeginRequestinsideMvcApplicationMake sure:
Namespace matches
Inherits="SmartRestaurantManagement.MvcApplication"Clean & rebuild
Reload the site
Bottom line
Your culture code is correct
It was placed in the wrong file
Move it to
Global.asax.csinside the classYour app will run and dates will format correctly on Somee
Emmmanuel FIADUFEPosted Jan 23, 2026, 2:24 PM
When I open the Global.asax.cs, I found this line of code and I pasted your code below.
<%@ Application Codebehind="Global.asax.cs" Inherits="SmartRestaurantManagement.MvcApplication" Language="C#" %>
Emmmanuel FIADUFEPosted Jan 23, 2026, 2:19 PM
Hello Jignesh Kumar
Where do I place your code.
Emmmanuel FIADUFEPosted Jan 23, 2026, 2:18 PM
Hello Raghunath Bhukan
After modifying my Global.asax.cs, with your code this is the error message that came up when when I went to the page.
protected void Application_BeginRequest()
{
var culture = new System.Globalization.CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
}
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The content in the application file is not valid.
Source Error:
Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="SmartRestaurantManagement.MvcApplication" Language="C#" %> Line 2: protected void Application_BeginRequest() Line 3: { Line 4: var culture = new System.Globalization.CultureInfo("en-GB");
Raghunath BhukanPosted Jan 22, 2026, 6:09 AM
Root Cause (Why it works locally but not on Somee)
1. SQL
datehas NO formatIn SQL Server:
Does not store any format (
yyyy-MM-dd,dd-MM-yyyy, etc.)It stores only a pure date value
The format is applied only when the date is converted to a string
2. Different server culture settings
Local machine ? usually
en-GBor similarSomee server ? usually
en-USBecause of this:
en-GBdisplays dates asdd-MM-yyyyen-USdisplays dates asMM-dd-yyyyThis explains why your formatting works locally but not after hosting.
Why using
nvarcharfor dates is dangerousYou are absolutely right to be concerned.
If dates are stored as strings:
Incorrect sorting
Example:
"02-01-2024"appears greater than"15-12-2023"Broken filtering using
BETWEEN,>=,<=Poor query performance
SQL date functions cannot be used
Indexes become ineffective
For production systems, dates should never be stored as strings.
Correct & Professional Solution (Best Practice)
1. Keep SQL column as
DATEorDATETIME2. NEVER format dates in SQL
Avoid doing this:
Formatting should not happen in SQL.
3. Format dates in MVC (NOT SQL)
In Razor views:
Or:
4. For input fields (Create / Edit)
HTML date inputs require
yyyy-MM-dd:This is mandatory for browser compatibility.
5. Set Global Culture in MVC (IMPORTANT)
This step fixes the Somee hosting issue permanently.
In
Global.asax.cs(ASP.NET MVC):This forces
dd-MM-yyyyregardless of the server’s regional settings.6. Filtering sales data (SAFE way)
Always filter using
DateTime, not strings:Benefits:
Correct results
Uses SQL indexes
Fast and reliable
What NOT to do
Do not store dates as
nvarcharDo not rely on SQL formatting
Do not compare date strings
Do not assume hosting culture matches local culture
Summary (What you should do now)
Keep SQL column as
DATESet application culture to
en-GBFormat dates only in MVC views
Filter data using
DateTime, not stringsThis approach is industry-standard, scalable, and production-safe.
Note - Use UTC if ANY of these are true:
Users are in multiple time zones
You log events (sales, audits, transactions)
You may expand to other countries later
You want consistent timestamps across servers
Jignesh KumarPosted Jan 22, 2026, 2:58 AM
Hello,
You can do this on your razor page,
Or if nullable:
If model binding / parsing is failing on Somee : Explicitly parse with culture: