You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MVC中‘/.well-known/apple-app-site-association’路径报错解决方案咨询

Fixing "Controller not found" for apple-app-site-association in ASP.NET MVC

Hey there, I’ve dealt with this exact issue before—let’s get your site sorted out so those errors stop popping up. First, a quick context: those /apple-app-site-association and /.well-known/apple-app-site-association paths are required by Apple’s Universal Links and App Attestation features, which validate the connection between your app and website. The error happens because ASP.NET MVC’s routing system is trying to map those paths to a controller (which doesn’t exist) instead of treating them as static content or a dedicated endpoint.

Here are the most reliable solutions to fix this:

Option 1: Serve as a static file (simplest approach)

This is the easiest way—just let IIS serve the file directly without involving MVC routing.

  1. Add the file to your site

    • Create a .well-known folder in your site’s root directory.
    • Place your apple-app-site-association file (no file extension, it’s just named that) both in the root and inside .well-known (covering both paths avoids missing requests). The file should be valid JSON matching Apple’s schema.
  2. Tell MVC to ignore these routes
    Open your RouteConfig.cs and add these lines before your default route:

    // Ignore direct apple-app-site-association request
    routes.IgnoreRoute("/apple-app-site-association");
    // Ignore the .well-known variant
    routes.IgnoreRoute("/.well-known/apple-app-site-association");
    

    This prevents MVC from trying to find a controller for these paths.

  3. Configure IIS to handle the file
    Since the file has no extension, IIS might not know how to serve it. Add this to your web.config under <system.webServer>:

    <staticContent>
      <mimeMap fileExtension="." mimeType="application/json" />
    </staticContent>
    

    This tells IIS to serve the no-extension file as JSON, which is what Apple expects.

Option 2: Use a controller action (if you need dynamic content)

If you need to generate the association content dynamically (e.g., based on environment), create a dedicated controller:

  1. Create the controller

    public class AppleAssociationController : Controller
    {
        public ActionResult GetAssociation()
        {
            // Load your JSON content—could be from a file, database, etc.
            var associationContent = System.IO.File.ReadAllText(Server.MapPath("~/apple-app-site-association"));
            // Return with the correct MIME type
            return Content(associationContent, "application/json");
        }
    }
    
  2. Map the routes
    Add these routes to RouteConfig.cs before your default route:

    routes.MapRoute(
        name: "AppleAppSiteAssociation",
        url: "apple-app-site-association",
        defaults: new { controller = "AppleAssociation", action = "GetAssociation" }
    );
    
    routes.MapRoute(
        name: "AppleAppSiteAssociationWellKnown",
        url: ".well-known/apple-app-site-association",
        defaults: new { controller = "AppleAssociation", action = "GetAssociation" }
    );
    

How to verify it’s working

After deploying your changes:

  • Visit both URLs directly in a browser (or use curl/postman) to confirm you get the correct JSON content with a 200 OK status.
  • Check your logs—those System.Web.HttpException errors should no longer appear.

A quick note: Apple requires this file to be served over HTTPS (unless you’re testing locally), so make sure your Danish deployment has a valid SSL certificate. Also, double-check that your apple-app-site-association JSON includes the correct Team ID and Bundle IDs for your iOS apps, otherwise Apple won’t recognize it even if the file is accessible.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:01:52