尝试在南希返回 rss 源时出现异常

本文关键字:异常 rss 返回 | 更新日期: 2023-09-27 17:55:19

我的 Web 应用程序遇到了问题。当我在本地运行它时,一切正常,我得到了一个 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;
}

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

如果这取决于,我使用 .net 4.5 和 Nancy 1.4.2

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

在日志中,我有以下错误:

无效的 URI

:无法确定 URI 的格式。

使用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)
    };
}

尝试在南希返回 rss 源时出现异常

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

urlFromConfig

anotherUrlFromConfig

设置为不带

http://

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