C# 在OWIN身份验证期间获取路由属性?
我第一次使用WebAPI2.0和OWIN中间件构建RESTfulWebService,它使用带有刷新令牌的令牌身份验证。 这个博客在这方面帮了我很大的忙: 在身份验证期间,我需要一个值来指定它应该连接到哪个数据库。 我可以使用C# 在OWIN身份验证期间获取路由属性?,c#,web-services,http,asp.net-web-api2,owin,C#,Web Services,Http,Asp.net Web Api2,Owin,我第一次使用WebAPI2.0和OWIN中间件构建RESTfulWebService,它使用带有刷新令牌的令牌身份验证。 这个博客在这方面帮了我很大的忙: 在身份验证期间,我需要一个值来指定它应该连接到哪个数据库。 我可以使用stringdbid=context.Parameters.Get(“dbid”),它从请求正文获取值 现在,我最初的计划是在控制器中指定over属性路由: [RoutePrefix("api/{dbid:length(2)}")] public class Custom
stringdbid=context.Parameters.Get(“dbid”)代码>,它从请求正文获取值
现在,我最初的计划是在控制器中指定over属性路由:
[RoutePrefix("api/{dbid:length(2)}")]
public class CustomersController : ApiController
{
// GET: api/dbid/Customers/id
// GET: api/XX/Customers/5
[Authorize]
[Route("Customer/{id}")]
[ResponseType(typeof(Customers))]
public Customers GetCustomer(string dbid, string id)
{
Customers c = null;
Connection cn = new Connection(dbid);
使用令牌端点路径也可以这样做吗?
类似于设置TokenEndpointPath=newpathstring(“/{dbid:length(2)}/token”),
和以某种方式访问路由属性,提取id?您不能像在身份验证中那样访问路由参数,因为身份验证中间件在WebApi中间件之前,而且路由参数在WebApi中是一个术语,所以您不能在身份验证中使用它
然而,若dbid
总是在url的同一段中或者在查询字符串中,那个么您可以解析请求uri并自己获取它