azure - Azure 中的重定向服务 (302),最好的方法是什么?

标签 azure azure-functions azure-web-app-service

我需要创建一个重定向器,将用户重定向到外部域,同时保留查询参数和一个附加参数。

例如当用户访问时 https://contoso.com/redirect?docId=123,它将用户重定向到 https://contoso-v2.com/home?docId=123&token=xxxxxxx

一旦用户访问 https://contoso.com/redirect?docId=123,此终结点将处理信息(来自查询参数)并生成需要附加到目标 URL 中的 token .

Azure 中最有效、最好的方法是什么?编写一个简单的 Azure Web App 还是有更好的方法?

最佳答案

您可以使用Azure FunctionHttpTrigger Binding 。与consumption plan成本将是最小的(1 million invocations are free in pay-as-you-go plan)。

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    var uri = req.RequestUri;
    var updatedUri = ReplaceHostInUri(uri, "contoso-v2.com");

    //return req.CreateResponse(HttpStatusCode.OK, "Original: " + uri + " Updated: " + updatedUri);
    return req.CreateResponse(HttpStatusCode.Found, updatedUri);
}

private static string ReplaceHostInUri(Uri uri, string newHostName) {
    var builder = new UriBuilder(uri);

    builder.Host = newHostName;
    //Do more trasformations e.g. modify path, add more query string vars

    return builder.Uri.ToString();
}

关于azure - Azure 中的重定向服务 (302),最好的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55441112/

相关文章:

azure - 如何将现有的 Block Blob 转换为 PageBlob

node.js - 在 Azure Web App 中访问 SSL 证书

azure - provider.azurerm 不支持资源类型 "azurerm_network_interface_security_group_association"

Python - 如何在 Azure 表存储中进行范围查询

azure - 将静态网站返回给 Function proxy

azure - 当我想要访问 Postman 中受 Azure AD 保护的 Azure 函数 API 时,应为 "scope"选项赋予什么值

c# - 无法读取 local.settings.json 中定义的连接字符串

javascript - Azure Function - js - 运行不正确,但日志中没有错误

c# - 在 Azure 应用服务器中使用 Hangfire 进行计算成本高昂的操作的替代方案

azure - Web 应用程序(应用程序服务)上的 IP 限制