问题
How can i serve a locale appropriate .resx
file to a http client in ASP.NET?
e.g.
GET /App_LocalResources/MeshModdler.resx
Background
i have a client-side binary that needs to ask a web-server for the appropriate language resources (i.e. it does not have all possible translations; it asks for the one it needs).
Right now the client-side binary prefers to be given an xml file containing all the localized resources (strings, etc). This XML file has a format that looks curiously like Microsoft's resx
format (one might think the format was copied - and they would not be wrong).
Ideally we can use the power of an ASP.NET web-server to locate the appropriate resx file based on the http client's Accept-Language
, e.g.
GET /App_LocalResources/MeshModdler.resx
Accept-Language: az-Cyrl-AZ
Ideally the web-server would try to return, in order of preference:
MeshModdler.az-Cyrl-AZ.resx
MeshModdler.az-AZ.resx
MeshModdler.az.resx
MeshModdler.resx
But instead the server returns:
HTTP/1.1 404 Not Found
Bonus Chatter
i know this is not possible. So in addition to a cannot be done
answer, i would also accept an answer that just does what i want:
- harnesses the power of an ASP.NET web-server to perform resource resolution and fallback
- allows new localization
resx
files to be dropped into a folder and have them picked up will not require resorting to creating a dummy page that builds what looks like a
resx
file, but has to thunk every entry with:<root> <data name="TesselateMesh.Caption"> <value><%$ Resources:MeshModdler, TesselateMesh.Caption1 %></value> </data> ... </root>
Additional Chatter
The hack for now will be to rename the resx
files to xml
:
MeshModdler.az-Cyrl-AZ.xml
MeshModdler.az-AZ.xml
MeshModdler.az.xml
MeshModdler.xml
And re-invent the fallback code:
GET /MeshModdler.az-Cyrl-AZ.xml
404 Not found
GET /MeshModdler.az-AZ.xml
404 Not found
GET /MeshModdler.az.xml
200 Ok
But it would be nice to work with ASP.NET, not against it.
回答1:
You can create an ASHX file that takes a resource name file and looks up the correct .ResX
file on the server. (moving your current fallback logic to /GetResource.ashx?Name=MeshModeler
)
来源:https://stackoverflow.com/questions/9267297/how-to-serve-resx-file-in-asp-net