Overview
When users edit documents in OnlyOffice, the Document Server sends HTTP callbacks to your application to notify you of status changes and provide the edited document. TheOnlyOfficeHandler.ashx endpoint handles these callbacks and automatically saves document changes.
The Callback Flow
Callback URL Configuration
The callback URL is automatically set when you load a document:OnlyOfficeEditor.ascx.cs:109-110
Public Base URL
UsePublicBaseUrl to ensure OnlyOffice can reach your application:
Callback Handler Implementation
The callback handler processes POST requests from OnlyOffice:OnlyOfficeHandler.ashx.cs:71-109
Callback Payload Structure
OnlyOffice sends a JSON payload with the callback:OnlyOfficeHandler.ashx.cs:151-155
Document Status Codes
OnlyOffice sends different status codes to indicate document state:| Status | Name | Description | Handler Action |
|---|---|---|---|
| 0 | Not found | Document not found in cache | None |
| 1 | Editing | Document is being edited | None |
| 2 | Ready | Document ready to save | Download and save |
| 3 | Save error | Error while saving | None |
| 4 | Closed | Document closed without changes | None |
| 6 | Force save | Force save request | Download and save |
| 7 | Corrupted | Document corrupted or error | None |
The handler only processes status 2 (ready to save) and 6 (force save), which indicate the document has been edited and needs to be saved.
Status 2: Document Ready to Save
Sent when:- User closes the document after making changes
- All users finish editing (in collaborative mode)
- Automatic periodic save triggers
Status 6: Force Save
Sent when:- Application explicitly requests document save via API
- Admin forces save in OnlyOffice
- Scheduled backup triggers
Saving Process
When the handler receives status 2 or 6:- Extract file ID from query string parameter
- Locate original file in storage using the file ID
- Download edited document from OnlyOffice URL
- Replace original file with new content
- Return success response
{error: 0}
OnlyOfficeHandler.ashx.cs:89-100
File Storage
Documents are stored in~/App_Data/uploads/:
OnlyOfficeHandler.ashx.cs:36-41
File Resolution
Files are stored with GUID names and original extensions:OnlyOfficeHandler.ashx.cs:43-49
- File ID:
a1b2c3d4e5f6g7h8 - Stored as:
~/App_Data/uploads/a1b2c3d4e5f6g7h8.docx
Response Format
The handler must return a JSON response:Success Response
Error Response
OnlyOfficeHandler.ashx.cs:102-108
Capturing Edited Documents
Beyond automatic saves, you can manually capture edited documents using theCaptureTriggerId feature:
- JavaScript captures the current document state
- Downloads the document from OnlyOffice
- Encodes as Base64 and stores in hidden field
- Triggers postback
Error Handling
Common Callback Failures
Callback URL not reachable
Callback URL not reachable
Symptom: Documents don’t save, no callbacks receivedCauses:
- Firewall blocking OnlyOffice server
- Incorrect
PublicBaseUrlconfiguration - SSL certificate issues
File not found errors
File not found errors
Symptom: Callback receives but file isn’t updatedCauses:
- File ID mismatch
- File deleted from storage
- Permissions issue on uploads directory
JWT authentication failures
JWT authentication failures
Symptom: Callbacks rejected with 401 or 403 errorsCauses:
- JWT secret mismatch
- OnlyOffice expecting JWT but not receiving it
Logging Callbacks
Add logging to troubleshoot callback issues:Testing Callbacks Locally
Using ngrok
For local development, use ngrok to expose your local server:Using IIS Express
Enable external connections in.vs/config/applicationhost.config:
Best Practices
Callback Handler Guidelines:
- Always return a response - OnlyOffice waits for
{error: 0}or{error: 1} - Handle exceptions gracefully - Return
{error: 1}on any failure - Log callback data - Essential for debugging save issues
- Verify file exists - Check storage before attempting to save
- Use HTTPS - OnlyOffice requires secure callbacks in production
- Test reachability - Ensure OnlyOffice can reach your callback URL
Security Considerations
IP Whitelisting Example
Related Topics
- Configuration Properties - Set up callback URLs
- JWT Authentication - Secure callbacks
- Document Types - Understand different save behaviors by document type