尝试 return 南希的 rss 提要时出现异常

Exception while trying to return a rss feed in Nancy

我的网络应用程序遇到了问题。 当我 运行 它在本地一切正常时,我得到一个 rss 提要。但是当我将我的应用程序部署到远程机器时。我收到这样的错误:

Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'UriFormatException'
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
Locations inspected: views/Renderer/UriFormatException-pl,views/Renderer/UriFormatException,Renderer/UriFormatException-pl,Renderer/UriFormatException,views/UriFormatException-pl,views/UriFormatException,UriFormatException-pl,UriFormatException
Root path: C:\WebAppPath
If you were expecting raw data back, make sure you set the 'Accept'-header of the request to correct format, for example 'application/json'
   at Nancy.ViewEngines.DefaultViewFactory.GetRenderedView(String viewName, Object model, ViewLocationContext viewLocationContext)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at CallSite.Target(Closure , CallSite , DefaultViewFactory , Object , Object , ViewLocationContext )
   at Nancy.ViewEngines.DefaultViewFactory.RenderView(String viewName, Object model, ViewLocationContext viewLocationContext)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at CallSite.Target(Closure , CallSite , IViewFactory , String , Object , ViewLocationContext )
   at Nancy.Responses.Negotiation.ViewProcessor.Process(MediaRange requestedMediaRange, Object model, NancyContext context)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at CallSite.Target(Closure , CallSite , IResponseProcessor , String , Object , NancyContext )
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.NegotiateResponse(IEnumerable`1 compatibleHeaders, NegotiationContext negotiationContext, NancyContext context)
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.CreateResponse(IList`1 compatibleHeaders, NegotiationContext negotiationContext, NancyContext context)
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.NegotiateResponse(Object routeResult, NancyContext context)
   at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)

这是我的代码的一部分,负责生成 rss 提要..

Get["GetFeed"] = _ => 
{
    var feed = _feedProvider.GetFeed();
    var sw = new StringWriter();
    using (var xmlWriter = new XmlTextWriter(sw))
    {
        xmlWriter.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='format.xsl'");
        xmlWriter.Formatting = Formatting.Indented;
        new Rss20FeedFormatter(feed).WriteTo(xmlWriter);
    }

    var res = (Response) sw.ToString();
    res.ContentType = "text/xml";
    return res;
}

我还有另一个 returns 简单 json 的操作,它们在本地机器和远程机器上都可以正常工作。我不知道为什么这个 returns 与 json/html/plain 文本不同的特定代码在远程机器上没有 运行。

如果视情况而定,我使用 .net 4.5 和 Nancy 1.4.2

编辑我添加了一个 log4net 来检查日志以获得更复杂的错误描述。

在日志中我有以下错误:

Invalid URI: The format of the URI could not be determined.

使用 Uri 的唯一部分代码是 _feedProvider.GetFeed() 函数。

public SyndicationFeed Get()
{
    var alternateLink = new Uri(urlFromConfig);
    var items = GetItems();
    return new SyndicationFeed("Title", "", alternateLink, items)
    {
        Copyright = new TextSyndicationContent(""),
        Language = "pl-PL",
        ImageUrl = new Uri(anotherUrlFromConfig)
    };
}

问题是我的 app.config 中的任何环境都有不同的值。所以在本地机器上一切正常。但是在远程机器上我得到错误,因为

urlFromConfig

anotherUrlFromConfig

设置为没有

的网址

http://

前缀,所以当我添加它时一切都开始正常工作。