【问题标题】:asp.net web api in sitecore站点核心中的 asp.net web api
【发布时间】:2013-07-06 03:38:22
【问题描述】:

我想在 sitecore 中使用 ASP.Net Web API (http://asp.net/Webapi)。尽管我添加了

  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

在 web.config 中。提到了必要的组件。但是,还是打不通。。 我正在使用 Web 应用程序项目。我在 Web 应用程序项目中做了一些示例,它们工作正常。但是,与 sitecore 集成让我很难受。

请输入任何内容..?

谢谢

【问题讨论】:

    标签: asp.net-mvc-3 asp.net-web-api sitecore


    【解决方案1】:

    这可能是 Sitecore 是个聪明人,它打断了您尝试在内容树中查找 URL 的请求。

    如果您知道要调用的 URL(或它们的部分路径),则可以将它们添加到配置中的 IgnoreUrlPrefixes 设置中。

    在这里查看不错的小帖子:

    http://sitecoreblog.alexshyba.com/2011/05/teach-sitecore-to-ignore-directory.html

    【讨论】:

      【解决方案2】:

      如果您正在创建 webapi 路由,您还可以在 RequestPipeline 中执行一个步骤,如果它找到与当前 URL 匹配的路由,则会中止管道

      public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
          {
              RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context));
      
              if (routeData != null)
              {
                  HttpContext.Current.RemapHandler(routeData.RouteHandler.GetHttpHandler(HttpContext.Current.Request.RequestContext));
                  args.AbortPipeline();
              }
          }
      

      这样你就可以在它解析数据库和站点后立即设置它,这样你就可以使用 Sitecore.Context 来处理数据库访问等。

      【讨论】:

        猜你喜欢
        • 2023-01-22
        • 1970-01-01
        • 2020-01-24
        • 2017-01-30
        • 2017-08-25
        • 2021-12-08
        • 1970-01-01
        • 2021-06-25
        • 1970-01-01
        相关资源
        最近更新 更多