NuGet.Server 返回 404 错误 [英] NuGet.Server returns 404 error

查看:18
本文介绍了NuGet.Server 返回 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 说明 设置和托管我自己的 NuGet 提要.我在 Windows 2012 (IIS 8.5) 机器上运行 Web 应用程序.

我构建并运行解决方案并获取 default.aspx 页面...

上面写着您正在运行 NuGet.Server v2.8.60318.667"和单击此处查看您的包裹".

当我单击此处"链接时,我收到404 - 找不到文件或目录".错误.

  • 我可以成功运行 nuget.exe 推送命令来放置包Nuget 服务器;但是尝试运行时出现 404 错误nugget.exe 列表命令.
  • 我已经重启了 IIS 和服务器
  • 我已从头开始重建 NuGet.Server Web 应用程序.
  • 我尝试在 Windows 7 机器上托管 NuGet.Server,但没有成功.
  • Web.Config 有以下条目

  • web.config 也有一个条目将 .nupkg 扩展注册为 mimeType="application/zip"

似乎 url 路由不起作用,但我似乎无法确定我做错了什么.某些东西阻止了 odata 提要工作.

我知道 NuGet 服务器有很棒的 3rd 方实现,但我真的很想让免费的服务器运行起来,而且看起来应该很容易.任何想法或故障排除提示将不胜感激.

解决方案

这个答案扩展了 AndrewD 的答案上留下的评论.

和他一样,我从一个 VB 项目开始,最终与 OP 在同一个阵营.然而,对我有用的是在这两个文件中将所有 C# 代码转换为 VB.

  1. 默认.aspx
  2. NuGetODataConfig.cs(将这个替换为新文件:NuGetODataConfig.vb)

为了完整起见,我将这些文件的转换后内容包括在下面.

<小时>

默认.aspx

<%@ Page Language="VB" %><%@ 导入命名空间="NuGet.Server" %><%@ 导入命名空间="NuGet.Server.App_Start" %><%@ 导入命名空间="NuGet.Server.Infrastructure" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 过渡//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><title>NuGet 私有存储库</title><风格>正文 {字体系列:Calibri;}</风格></头><身体>

<h2>你正在运行 NuGet.Server v<%= Gettype(NuGetODataConfig).Assembly.GetName().Version %></h2><p>点击 <a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/Packages") %>">这里</a>查看您的包裹.</p><fieldset style="width:800px"><legend><strong>存储库 URL</strong></legend>在包管理器设置中,将以下 URL 添加到包来源:<块引用><strong><%= Helpers.GetRepositoryUrl(Request.Url, Request.ApplicationPath) %></strong></blockquote><% if string.IsNullOrEmpty(ConfigurationManager.AppSettings("apiKey")) Then %>使用 <a href="https://www.nuget.org/downloads">NuGet 命令行工具</a> 启用将包推送到此提要的功能(nuget.exe),设置<code>apiKey</code>web.config 中的应用程序设置.<% 其他 %>使用下面的命令,使用 <a href="https://www.nuget.org/downloads">NuGet 命令行工具</a> 将包推送到此提要.(nuget.exe).<块引用><strong>nuget.exe push {包文件} {apikey} -Source <%= Helpers.GetPushUrl(Request.Url, Request.ApplicationPath) %></strong></blockquote><% end if %></字段集><% if Request.IsLocal Then %><fieldset style="width:800px"><legend><strong>添加包</strong></legend>将包添加到文件夹中的提要放置包文件(.nupkg 文件)<code><% = PackageUtility.PackagePhysicalPath %></code><br/><br/>点击<a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/clear-cache") %>">这里</a>清除包缓存.</字段集><% 结束如果 %></div></身体></html>

NuGetODataConfig.vb

导入 System.Net.Http导入 System.Web.Http导入 System.Web.Http.ExceptionHandling导入 System.Web.Http.Routing导入 NuGet.Server导入 NuGet.Server.Infrastructure导入 NuGet.Server.V2<程序集:WebActivatorEx.PreApplicationStartMethod(GetType(MGInuGet.App_Start.NuGetODataConfig), "Start")>命名空间 MGInuGet.App_Start公共模块 NuGetODataConfig公共子开始()ServiceResolver.SetServiceResolver(新的 DefaultServiceResolver())暗淡配置为 HttpConfiguration = GlobalConfiguration.ConfigurationNuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(配置,NuGetDefault",nuget",PackagesOData")config.Services.Replace(GetType(IExceptionLogger),新 TraceExceptionLogger())Trace.Listeners.Add(New TextWriterTraceListener(System.Web.Hosting.HostingEnvironment.MapPath("~/NuGet.Server.log")))Trace.AutoFlush = Trueconfig.Routes.MapHttpRoute(name:="NuGetDefault_ClearCache",routeTemplate:="nuget/clear-cache",默认值:=使用 {Key .controller = "PackagesOData", Key .action = "ClearCache"} 新建,约束:= 新的 {Key .httpMethod = 新的 HttpMethodConstraint(HttpMethod.Get)})结束子端模块结束命名空间

I have followed the instructions to setup and host my own NuGet feed. I am running the web application on a Windows 2012 (IIS 8.5) box.

I build and run the solution and get the default.aspx page...

Which says "You are running NuGet.Server v2.8.60318.667" and "Click here to view your packages".

When I click on the "here" link I get a "404 - File or directory not found." error.

  • I can successfully run a nuget.exe push command to put packages on the Nuget server; however I get a 404 error when attempting to run nugget.exe list command.
  • I have restarted IIS and the server
  • I have rebuilt the NuGet.Server web application from scratch.
  • I have tried hosting the NuGet.Server on a Windows 7 box with no success.
  • The Web.Config has the following entry

    <modules runAllManagedModulesForAllRequests="true">
    

  • The web.config also has an entry to register the .nupkg extension as mimeType="application/zip"

It seems like the url routing is not working, but I can't seem to pin down what I am doing wrong. Something is preventing the odata feed from working.

I know there are great 3rd party implementations of NuGet server, but I would really like to just get the free one working and it seems like it should be so easy. Any thoughts or troubleshooting tips would be appreciated.

解决方案

This answer expands the comment left on AndrewD's answer.

Like him, I started out with a VB project and I ended up in the same camp as OP. What worked for me however was converting all C# code into VB, within these two files.

  1. Default.aspx
  2. NuGetODataConfig.cs (replaced this one with a new file: NuGetODataConfig.vb)

For the sake of completion, I'm including the post-converted contents of these files below.


Default.aspx

<%@ Page Language="VB" %>
<%@ Import Namespace="NuGet.Server" %>
<%@ Import Namespace="NuGet.Server.App_Start" %>
<%@ Import Namespace="NuGet.Server.Infrastructure" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>NuGet Private Repository</title>
    <style>
        body { font-family: Calibri; }
    </style>
</head>
<body>
    <div>
        <h2>You are running NuGet.Server v<%= Gettype(NuGetODataConfig).Assembly.GetName().Version %></h2>
        <p>
            Click <a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/Packages") %>">here</a> to view your packages.
        </p>
        <fieldset style="width:800px">
            <legend><strong>Repository URLs</strong></legend>
            In the package manager settings, add the following URL to the list of 
            Package Sources:
            <blockquote>
                <strong><%= Helpers.GetRepositoryUrl(Request.Url, Request.ApplicationPath) %></strong>
            </blockquote>
            <% if string.IsNullOrEmpty(ConfigurationManager.AppSettings("apiKey")) Then %>
            To enable pushing packages to this feed using the <a href="https://www.nuget.org/downloads">NuGet command line tool</a> (nuget.exe), set the <code>apiKey</code> appSetting in web.config.
            <% else  %>
            Use the command below to push packages to this feed using the <a href="https://www.nuget.org/downloads">NuGet command line tool</a> (nuget.exe).
            <blockquote>
                <strong>nuget.exe push {package file} {apikey} -Source <%= Helpers.GetPushUrl(Request.Url, Request.ApplicationPath) %></strong>
            </blockquote>
            <% end if %>
        </fieldset>

        <% if Request.IsLocal Then  %>
        <fieldset style="width:800px">
            <legend><strong>Adding packages</strong></legend>

            To add packages to the feed put package files (.nupkg files) in the folder
            <code><% = PackageUtility.PackagePhysicalPath %></code><br/><br/>

            Click <a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/clear-cache") %>">here</a> to clear the package cache.
        </fieldset>
        <% End If %>
    </div>
</body>
</html>

NuGetODataConfig.vb

Imports System.Net.Http
Imports System.Web.Http
Imports System.Web.Http.ExceptionHandling
Imports System.Web.Http.Routing
Imports NuGet.Server
Imports NuGet.Server.Infrastructure
Imports NuGet.Server.V2

<Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(MGINuGet.App_Start.NuGetODataConfig), "Start")>

Namespace MGINuGet.App_Start
    Public Module NuGetODataConfig
        Public Sub Start()
            ServiceResolver.SetServiceResolver(New DefaultServiceResolver())

            Dim config As HttpConfiguration = GlobalConfiguration.Configuration

            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData")

            config.Services.Replace(GetType(IExceptionLogger), New TraceExceptionLogger())

            Trace.Listeners.Add(New TextWriterTraceListener(System.Web.Hosting.HostingEnvironment.MapPath("~/NuGet.Server.log")))
            Trace.AutoFlush = True

            config.Routes.MapHttpRoute(name:="NuGetDefault_ClearCache",
                                       routeTemplate:="nuget/clear-cache",
                                       defaults:=New With {Key .controller = "PackagesOData", Key .action = "ClearCache"},
                                       constraints:=New With {Key .httpMethod = New HttpMethodConstraint(HttpMethod.Get)})
        End Sub
    End Module
End Namespace

这篇关于NuGet.Server 返回 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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