asp.net - 将旧帖子重定向到 ServiceStack API

标签 asp.net asp.net-mvc servicestack

我有一个运行 ServiceStack v3.9.71 的 ASP.Net MVC 站点。我有一个新的 ServiceStack API,已配置为在 ~/api/* 上可用,但需要将 POST 请求从旧位置 ~/service/* 重定向到新 API然而我即将摆脱困境。

我尝试过使用 url 重定向,但这样做时 POST 变成 GET 并且 POST 数据丢失。

<rule name="GetVenuesByLocation" stopProcessing="true">
    <match url="^service/getvenuelistbylocation/$" />
    <action redirectType="Temporary" type="Redirect" url="/api/VenueListByLocation" />
</rule>

这可以实现吗?如果可以的话,有人可以指出我正确的方向吗?

谢谢,西蒙

最佳答案

评论中的回答和讨论。添加答案以便其他人更容易找到解决方案。

临时重写规则(在问题内)是正确的,并且将执行 307 POST 来维护原始值。

问题是现有的重定向重写规则在命中临时重写规则之前创建了 301。 301 会丢失数据。

Per ProNotion - 事实证明该规则是正确的,但需要在强制尾随斜杠的规则之前添加。然后无论有没有尾部斜杠,它都可以工作!

关于asp.net - 将旧帖子重定向到 ServiceStack API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28463780/

相关文章:

asp.net - ASP.NET 中的 C++/CLI 组件出现 "module could not be found"错误

c# - 使用 Jquery 单击按钮的客户端数据注释验证

.net - 通过MVC Web API传输完整对象的好策略是什么?

c# - ServiceStack TypeLoadException - 未知来源

c# - 如何在没有 default.htm 页面的情况下使用 ServiceStack MVC 库

c# - 当反射类型本身是 List 时实例化通用 c# List

c# - IsPostBack Condition 的作用是什么?

c# - ServiceStack 服务可以包含多个方法吗?

c# - RestSharp 不反序列化 JSON 对象列表,始终为 Null

c# - ASP.NET MVC 中的 ViewModel 验证最佳实践