不带参数的Http路由和路由内的一个点 [英] Http route without parameters and a point inside the route

查看:117
本文介绍了不带参数的Http路由和路由内的一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用ApiController类创建一个Web服务.由于某些限制,我必须在路线本身中放置一个Point(terminal.journalentry).并将其用作基本URL.因此:

I'm currently creating a webservice using ApiController classes. Due to some restrictions I have to put a Point in the route itself (terminal.journalentry). And use this as the base URL. Thus:

http://localhost:59684/terminal.journalentry

作为呼叫的示例.现在,尽管我遇到了问题.

as example for a call. Now though I've run into Problems.

当我在此调用中使用以下代码时: http://localhost:59684/terminal.journalentry 它可以顺利运行.

When I use the following code with this call: http://localhost:59684/terminal.journalentry it works without a hitch.

public class JournalController : ApiController
{
        [HttpGet]
        [Route("terminal.journalentry/{id}")]
        public void WriteJournalEntry(int id)
        {

        }
}

尽管我需要使用不涉及任何参数的方法.但是当我尝试以下操作时:

Though I Need to use the method without any Parameters involved. But when I try the following:

public class JournalController : ApiController
{
        [HttpGet]
        [Route("terminal.journalentry")]
        public void WriteJournalEntry()
        {

        }
}

呼叫为: http://localhost:59684/terminal.journalentry 我得到:

HTTP错误404.0-找不到

HTTP Error 404.0 - Not Found

现在我的问题是:那里出了什么问题?为了使用上面的URL而不遇到错误,需要做什么?

Now my question is: What is wrong there and what Needs to be done in order to use the above URL without running into Errors?

根据被询问的内容编辑Routes.config的内容是什么

Edit as it was asked what the Content of Routes.config is:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

WebApiConfig.cs在寄存器中仅包含以下内容:config.MapHttpAttributeRoutes();

WebApiConfig.cs has only the following Content inside Register: config.MapHttpAttributeRoutes();

推荐答案

我认为您需要配置一个处理程序以忽略".journalentry".
通常,任何带有句号的东西都被认为是文件,我想这是在这里发生的情况.

I think you need to configure a handler to ignore the ".journalentry".
Usually anything with a fullstop is considered a file, and I imagine this is happening here.

在API的web.config中,尝试找到以下部分:
<system.webServer>
<handlers>

In the web.config for your API, try and find the following section:
<system.webServer>
<handlers>

并添加处理程序定义:

<add name="JournalEntryExtensionHandler" path="*.journalentry*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

您可能需要对路径通配符设置进行一些尝试.
当我之前完成此操作时,URL 结尾并带有文件名,因此路径例如是"* .jpg".

You might need to play around a bit with the path wildcard settings.
When I've done this previously the URL ended with a filename so the path was "*.jpg" for example.

这篇关于不带参数的Http路由和路由内的一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆