You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

ASP.NET Web应用集成Microsoft Teams实现会议创建与直接参会问询

Absolutely, this scenario is fully achievable with Microsoft Graph API and Teams' built-in integration capabilities. I’ve walked through this exact setup with ASP.NET apps before, so let’s break down the steps, code examples, and key details to get this working for you.

Core Setup: Azure AD App & Permissions

First, you’ll need to register your ASP.NET app in Azure Active Directory (Azure AD) to get access to Microsoft Graph:

  • Register the app: Go to Azure AD, create a new app registration, and note down your Tenant ID, Client ID, and Client Secret.
  • Configure permissions: Add the following application permission (since we’re creating meetings in the background after form submission) and get admin consent:
    • OnlineMeetings.ReadWrite.All
      If you want the submitting user to be the meeting organizer, use the delegated permission OnlineMeetings.ReadWrite instead, but that requires user authentication flows.

Step 1: Create Teams Meeting After Form Submission

Once your app is set up, you can use the Microsoft Graph SDK in your ASP.NET controller to create a meeting when the user submits their form. Here’s a code example:

Initialize the Graph Client

First, set up the Graph client with client credentials flow (for background operations):

using Microsoft.Graph;
using Azure.Identity;

// Replace these with your Azure AD app details
var tenantId = "your-tenant-id";
var clientId = "your-app-client-id";
var clientSecret = "your-app-client-secret";

var scopes = new[] { "https://graph.microsoft.com/.default" };
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(credential, scopes);

Create the Meeting from Form Data

In your form submission action method, pull the user’s date/duration input and create the meeting:

// Get form data (adjust based on your form model)
var startDate = DateTimeOffset.Parse(Request.Form["MeetingStart"]).ToUniversalTime();
var durationMinutes = int.Parse(Request.Form["MeetingDuration"]);
var endDate = startDate.AddMinutes(durationMinutes);
var meetingSubject = $"User Booked Meeting: {Request.Form["MeetingTopic"]}";

// Define the meeting details
var newMeeting = new OnlineMeeting
{
    StartDateTime = startDate,
    EndDateTime = endDate,
    Subject = meetingSubject,
    Participants = new MeetingParticipants
    {
        Organizer = new MeetingParticipantInfo
        {
            Identity = new IdentitySet
            {
                User = new Identity
                {
                    Id = "your-organizer-user-id", // Use a dedicated user ID for meetings
                    DisplayName = "Meeting Organizer"
                }
            },
            Upn = "organizer@yourdomain.com" // Corresponding UPN of the organizer user
        }
    },
    // Optional: Configure meeting settings
    AllowAttendeeToEnableCamera = true,
    AllowAttendeeToEnableMic = true
};

try
{
    // Create the meeting (use Users endpoint for app permissions)
    var createdMeeting = await graphClient.Users["your-organizer-user-id"]
        .OnlineMeetings
        .PostAsync(newMeeting);

    // Save the meeting join URL to your database (link to the user's submission)
    var meetingJoinUrl = createdMeeting.JoinWebUrl;

    // Return success message to the user, along with the join option
    ViewBag.SuccessMessage = "Your meeting has been booked successfully!";
    ViewBag.MeetingJoinUrl = meetingJoinUrl;
}
catch (ServiceException ex)
{
    // Handle Graph API errors (e.g., permission issues, invalid dates)
    ViewBag.ErrorMessage = $"Failed to create meeting: {ex.Message}";
}

Important: When using application permissions, you can’t use graphClient.Me—you must target a specific user (the meeting organizer) via graphClient.Users[userId].

Step 2: Let Users Join Directly from Your App

Once you have the JoinWebUrl from the created meeting, you have two easy ways to let users join without email:

Add a button to your success page that links directly to the meeting URL:

@if (!string.IsNullOrEmpty(ViewBag.MeetingJoinUrl))
{
    <a href="@ViewBag.MeetingJoinUrl" target="_blank" class="btn btn-primary mt-3">Join Your Meeting</a>
}

Clicking this will open the Teams web app or desktop client directly, no email required.

Option 2: Teams SDK Integration (Smoother Experience)

For a more integrated experience, use the Microsoft Teams JavaScript SDK to launch the meeting directly:

  1. Add the Teams SDK script to your page:
<script src="https://statics.teams.cdn.office.net/sdk/v1.16.0/js/MicrosoftTeams.min.js"></script>
  1. Initialize the SDK and add a join button handler:
microsoftTeams.initialize();

document.getElementById("join-teams-btn").addEventListener("click", function() {
    microsoftTeams.joinMeeting({
        meetingUrl: "@ViewBag.MeetingJoinUrl"
    });
});

This will trigger the Teams client (web or desktop) to open the meeting instantly, providing a more seamless user experience.

Key Things to Keep in Mind

  • Organizer User: You need a valid Azure AD user account to act as the meeting organizer—service principals can’t organize meetings directly. Create a dedicated service account for this purpose if needed.
  • Admin Consent: Make sure your Azure AD app’s permissions have been granted admin consent, otherwise Graph API calls will fail with permission errors.
  • Error Handling: Always catch ServiceException from Graph API to handle issues like invalid date ranges, missing permissions, or organizer user errors.
  • Meeting Persistence: Store the meeting details (join URL, start/end time) in your database linked to the user’s form submission so they can access it later.

Additional Enhancements

  • Add meeting reminders via Teams messages using Graph API’s ChatMessage endpoint.
  • Allow users to view their past booked meetings in your app, with direct join links.
  • Add validation for form inputs (e.g., ensure start date is in the future, duration is reasonable).

内容的提问来源于stack exchange,提问作者EBMRay

火山引擎 最新活动