How to Show a Web Page in a Teams Dialog in the Microsoft 365 Agents SDK in C#
A Teams dialog can show a web page of your own instead of an Adaptive Card. Your agent answers Teams' dialog request with the page's address, and Teams loads the page inside the dialog.
Syntax
The route and the answer, in the agent:
TeamsExtension.TaskModules.OnFetch("<dialog name>", handler);
// In the handler:
return new TaskModuleResponse
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new { title = "<title>", width = <width>, height = <height>, url = "<page address>" },
},
};
| Part | What it does |
|---|---|
OnFetch("<dialog name>", handler) | Calls handler when someone selects a card button whose data holds "msteams": { "type": "task/fetch" } and "task": "<dialog name>" |
TaskModuleResponseTypes.Continue | "Show this in the dialog" |
title | The dialog's title, under the app's name |
width, height | A number of pixels, or small, medium or large |
url | The address of the page the dialog shows |
The answer is the one a card dialog gets, with url where the card would be. Microsoft's Invoke and dismiss dialogs describes url as The URL of the page loaded as an <iframe> inside the dialog. The URL's domain must be in the app's validDomains array in your app manifest. And Use dialogs with bots adds: Each url and fallbackUrl must implement the HTTPS encryption protocol.
The card button that opens the dialog is the same as for a card dialog: How to Open a Teams Dialog from an Adaptive Card in the Microsoft 365 Agents SDK in C# explains it. TeamsExtension needs [TeamsExtension] on the agent class: How to Add the Teams Extension to an Agent in the Microsoft 365 Agents SDK in C# sets it up.
The Example
The agent for this post shares the office's holiday calendar. Any message gets a card with a Show holiday calendar button, which opens a dialog titled Holiday calendar. The dialog shows holidays.html, a page the agent serves itself: a table of three public holidays.
Prerequisites
- An agent that already runs in Microsoft Teams, in a personal chat, with the Teams extension added.
- A public HTTPS address for the agent, such as a dev tunnel's. Teams loads the page from it.
Step 1: Add the Page
In the project, create a folder named wwwroot and, in it, holidays.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Holiday calendar</title>
<style>
body { margin: 0; padding: 0 24px; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 0; border-bottom: 1px solid #d1d1d1; text-align: left; }
</style>
</head>
<body>
<table>
<tr><th>Date</th><th>Holiday</th></tr>
<tr><td>1 January</td><td>New Year's Day</td></tr>
<tr><td>1 May</td><td>Labour Day</td></tr>
<tr><td>25 December</td><td>Christmas Day</td></tr>
</table>
<script src="https://res.cdn.office.net/teams-js/2.60.0/js/MicrosoftTeams.min.js"
integrity="sha384-oM1pbPWSxyAWgEVI9GzHDR2xzdMMehbAdsl9cH5emcTxX9Qr/kE4IS/Ld5IdcLmy"
crossorigin="anonymous"></script>
<script>
microsoftTeams.app.initialize();
</script>
</body>
</html>
- The
<table>is the page's content: an ordinary web page, with its own style. - The first
<script>loads the Teams JavaScript library (TeamsJS) from Microsoft's CDN. How to Add the Teams JavaScript Library (TeamsJS) to a Web Page from the CDN explains the tag and itsintegrityhash. microsoftTeams.app.initialize()tells Teams the page has loaded. The page needs nothing else from Teams, so it doesn't wait for the answer. Without this call, Teams on the web showed a banner over the dialog about half a minute after it opened: Fixed: "If You're Having Issues with This App, Try the Desktop Version" in a Teams Dialog.
Step 2: Serve the Page from the Agent
In Program.cs, add app.MapStaticAssets(); after the agent's endpoints:
app.UseAgents();
app.MapDefaultAgentEndpoints();
app.MapStaticAssets();
app.Run();
MapStaticAssets() serves the files in wwwroot, so the page is at /holidays.html on the agent's address. How to Serve Static Files in ASP.NET Core with MapStaticAssets (C#) explains what it does. It lists the files when the project is built, so restart the agent with dotnet run after adding a page. A page added while the agent runs is still served in Development, with a warning: Fixed: The static asset was not found in the built time manifest in ASP.NET Core.
Step 3: Give the Agent Its Public Address
The url must be the address Teams uses to reach the page, the public HTTPS one. In appsettings.Development.json, add a PublicUrl setting with your dev tunnel's address:
{
"PublicUrl": "https://cdzngt35-3980.inc1.devtunnels.ms"
}
Use your own address: it's the one your bot's messaging endpoint starts with. PublicUrl is this example's own setting, not one the SDK reads. The agent reads it in the next step.
Step 4: Answer the Dialog Request with the Page's Address
using System.Text.Json.Nodes;
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Builder.State;
using Microsoft.Agents.Core.Models;
using Microsoft.Agents.Extensions.MSTeams;
using Microsoft.Teams.Apps.TaskModules;
namespace HolidayCalendar;
[TeamsExtension]
public partial class HolidayCalendarAgent : AgentApplication
{
private readonly string _pageUrl;
public HolidayCalendarAgent(AgentApplicationOptions options, IConfiguration configuration)
: base(options)
{
// PublicUrl is the agent's public HTTPS address: the dev tunnel's. The page is wwwroot/holidays.html.
_pageUrl = new Uri(new Uri(configuration["PublicUrl"]!), "holidays.html").ToString();
OnActivity(ActivityTypes.Message, SendCardAsync);
TeamsExtension.TaskModules.OnFetch("holidays", OpenPageAsync);
}
// Any message gets a card whose button opens the dialog.
private Task SendCardAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = "Next year's public holidays are out.", ["wrap"] = true },
},
["actions"] = new JsonArray
{
new JsonObject
{
["type"] = "Action.Submit",
["title"] = "Show holiday calendar",
["data"] = new JsonObject { ["msteams"] = new JsonObject { ["type"] = "task/fetch" }, ["task"] = "holidays" },
},
},
};
return turnContext.SendActivityAsync(MessageFactory.Attachment(new Attachment { ContentType = ContentTypes.AdaptiveCard, Content = card }), cancellationToken);
}
// task/fetch: the page's address. Teams opens the dialog and loads the page in it.
private Task<TaskModuleResponse> OpenPageAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
return Task.FromResult(new TaskModuleResponse
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new { title = "Holiday calendar", width = 400, height = 230, url = _pageUrl },
},
});
}
}

new Uri(new Uri(configuration["PublicUrl"]!), "holidays.html")joins the public address and the page's name intohttps://cdzngt35-3980.inc1.devtunnels.ms/holidays.html. The agent builds it once, when it starts.SendCardAsyncsends the card. Its button's data holds"msteams": { "type": "task/fetch" }and"task": "holidays".OnFetch("holidays", OpenPageAsync)routes the dialog request forholidays.OpenPageAsyncanswers withContinue, the dialog's title and size, andurl. Withurlinstead ofcard, Teams shows the page.
Step 5: List the Page's Domain in the Manifest
Teams loads a page in a dialog only from a domain in the validDomains list of your app's manifest. Open your app package's manifest.json and look for it. If the page's host isn't there, add it and raise the version:
"version": "1.0.1",
"validDomains": [
"cdzngt35-3980.inc1.devtunnels.ms"
]
Then upload the new package to Teams. How to Add a Valid Domain to a Microsoft Teams App Manifest shows each step, from editing the file to the upload.
Step 6: Open the Dialog in Teams
Start the agent with dotnet run, and send it any message in Teams. The card arrives:

Select Show holiday calendar. The dialog opens with the page in it:

Teams drew the dialog's frame: the app's icon and name, the title and the X. Everything under the title is the page.
If the dialog shows a Microsoft Dev Tunnels page that starts with You are about to connect to a developer tunnel instead of your page, that's the tunnel's warning for browsers: Fixed: "You Are About to Connect to a Developer Tunnel" in a Teams Dialog.
What Teams Sent and What the Agent Answered
The agent's log showed the invoke. Its value:
{
"data": {
"task": "holidays",
"type": "task/fetch"
},
"context": {
"theme": "default"
}
}
The SDK matched "task": "holidays" and sent the handler's answer back as the invoke's response:
{
"status": 200,
"body": {
"task": {
"type": "continue",
"value": {
"title": "Holiday calendar",
"width": 400,
"height": 230,
"url": "https://cdzngt35-3980.inc1.devtunnels.ms/holidays.html"
}
}
}
}
Then Teams asked for the page. With ASP.NET Core's request log on (the Microsoft.AspNetCore.Hosting.Diagnostics category at Information), the agent's output showed the invoke, then the page's request coming in through the tunnel:
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 POST http://localhost:3980/api/messages - application/json;+charset=utf-8 1424
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 POST http://localhost:3980/api/messages - 200 - application/json;+charset=utf-8 37.7970ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:3980/holidays.html - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:3980/holidays.html - 200 932 text/html 11.1161ms
The agent answered twice: the dialog's details through /api/messages, and the page itself, 932 bytes of HTML, from wwwroot.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
The agent's local address, http://localhost:3980, as url | Microsoft's docs require HTTPS, and localhost is each viewer's own computer | Use the public HTTPS address, such as the dev tunnel's |
The page's host missing from validDomains | The dialog stays empty, and Teams on the web shows a banner | Add the host and upload the package again |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Empty dialog, and the banner If you're having issues with this app, try the desktop version | The page's host isn't in validDomains, or the page never called app.initialize() | Fixed: "If You're Having Issues with This App, Try the Desktop Version" in a Teams Dialog |
| The dialog shows a dev tunnel warning | The tunnel's warning page for browsers | Fixed: "You Are About to Connect to a Developer Tunnel" in a Teams Dialog |
| A grey sad-page icon, and refused to connect | The page sends a Content Security Policy whose frame-ancestors doesn't include Teams on the web | Fixed: Framing '…' Violates the Following Content Security Policy Directive: "frame-ancestors …" in a Teams Dialog |
| Unable to reach app. Please try again. | The agent or its tunnel isn't running, or no route matched the task value | Start them, and check the agent's log for the invoke |
| A warning that the static asset was not found in the built time manifest | The page was added while the agent ran | Restart the agent: Fixed: The static asset was not found in the built time manifest in ASP.NET Core |
FAQ
Can the page send something back to the agent?
Yes. The page calls microsoftTeams.dialog.url.submit() with a result and your app's ID, and the agent gets it as a task/submit invoke: How to Submit a Web Page Dialog to Your Agent in the Microsoft 365 Agents SDK in C#.
Does the page have to come from the agent?
No. url can point to any HTTPS page whose domain is in validDomains. Serving it from the agent keeps one address to manage, and the dev tunnel already makes it public.
What is fallbackUrl?
An optional address next to url. Microsoft's Create and send dialogs describes it: If a client does not support the dialog feature, this URL is opened in a browser tab.
Conclusion
To show a web page in a Teams dialog, serve the page from the agent with app.MapStaticAssets(), answer the task/fetch invoke with a Continue response whose url is the page's public HTTPS address, and list the page's host in the manifest's validDomains. The page loads TeamsJS and calls app.initialize().
Additional Resources
- Invoke and dismiss dialogs, on Microsoft Learn: the dialog's properties.
- Use dialogs with bots, on Microsoft Learn.
- TaskModule.OnFetch Method, on Microsoft Learn.
Related
- How to Open a Teams Dialog from an Adaptive Card in the Microsoft 365 Agents SDK in C#
- How to Submit a Web Page Dialog to Your Agent in the Microsoft 365 Agents SDK in C#
- How to Show the Next Web Page in a Teams Dialog in the Microsoft 365 Agents SDK in C#
- How to Add a Valid Domain to a Microsoft Teams App Manifest
- Microsoft 365 Agents SDK Fundamentals in C# — Part 11: Show a Web Page in a Teams Dialog
