【发布时间】:2021-05-08 16:37:58
【问题描述】:
在我的 mvc 应用中,我想动态生成一个特定的 url:
https://myapp.corp.com/.well-known/microsoft-identity-association.json
此端点应根据 web.config 文件中的值生成一个小文件。所以我创建了这个控制器:
public class HostingController : Controller
{
// GET: Hosting
[OutputCache(Duration = 100, VaryByParam = "none")]
public ActionResult MicrosoftIdentityAssociation() => Json(new
{
associatedApplications = new[]
{
new { applicationId = WebConfigurationManager.AppSettings.Get("ClientId") }
}
});
}
我改变了这样的路由配置:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Azure domain registration",
".well-known/microsoft-identity-association.json",
new { controller = "Hosting", action= "MicrosoftIdentityAssociation" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
我希望 url 生成像这样的 json:
{
"associatedApplications": [
{
"applicationId": "1562019d-44f7-4a9d-9833-64333f52181d"
}
]
}
但是当我定位到 url 时,我得到了一个 404 错误。
怎么了?如何解决?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing