servicestack,favicon,ignoreroute,Routing,servicestack,Favicon,Ignoreroute" /> servicestack,favicon,ignoreroute,Routing,servicestack,Favicon,Ignoreroute" />

Routing ServiceStack 4:忽略回退路由中的favicon.ico

Routing ServiceStack 4:忽略回退路由中的favicon.ico,routing,servicestack,favicon,ignoreroute,Routing,servicestack,Favicon,Ignoreroute,我在ServiceStack.Razor上构建了一个或多或少是静态的网站,其路由定义为以下模式: 我试图忽略favicon.ico,但将“/”或“/en-us”这样的路径路由到HomeScenario。 其他示例路线有/{Lang}/cook或/{Lang}/Chee等 不幸的是,我目前的方法并没有忽略favicon.ico。我希望在不编写大量额外代码的情况下实现这一点 [FallbackRoute("/{Lang*}")] public class HomeScenario : Localiz

我在ServiceStack.Razor上构建了一个或多或少是静态的网站,其路由定义为以下模式: 我试图忽略favicon.ico,但将“/”或“/en-us”这样的路径路由到HomeScenario。 其他示例路线有/{Lang}/cook或/{Lang}/Chee等

不幸的是,我目前的方法并没有忽略favicon.ico。我希望在不编写大量额外代码的情况下实现这一点

[FallbackRoute("/{Lang*}")]
public class HomeScenario : LocalizedRequest
{

}

public class LocalizedRequest
{
    public LocalizedRequest()
    {
        Lang = "en-us";
    }
    public string Lang { get; set; }
}
这是默认的请求

[DefaultView("home")]
public object Get(HomeScenario request)
{
    var cacheKey = GetCacheKey ("home", request.Lang);
    return base.Request.ToOptimizedResultUsingCache (base.Cache, cacheKey, () => {
        var response = LoadJson<HomeScenarioResponse> (request.Lang, "home");
        return response;
    });
}
[DefaultView(“主页”)]
公共对象获取(HomeScenario请求)
{
var cacheKey=GetCacheKey(“home”,request.Lang);
返回base.Request.ToOptimizedResultUsingCache(base.Cache,cacheKey,()=>{
var response=LoadJson(request.Lang,“home”);
返回响应;
});
}

您可以忽略代码中的请求:

[DefaultView("home")]
public object Get(HomeScenario request)
{
    if (base.Request.PathInfo == "/favicon.ico")
        return HttpError.NotFound(request.PathInfo);

    var cacheKey = GetCacheKey ("home", request.Lang);
    return base.Request.ToOptimizedResultUsingCache (base.Cache, cacheKey, () => {
        var response = LoadJson<HomeScenarioResponse> (request.Lang, "home");
        return response;
    });
}
this.CatchAllHandlers.Add((httpmethod, pathInfo, filepath) => {

    if (pathInfo == "/favicon.ico") 
        return new NotFoundHttpHandler();

    return null; //continue processing request
});