Google.Apis.Books.v1.BooksService在本地IIS上有效,但在部署时无效

时间:2018-06-27 16:25:20

标签: asp.net google-api iis-express iis-8 google-books

我有一个非常简单的VB asp.NET(v4.6.1)网站,我是根据NuGet的Google图书api编写的。它包含一个文本框,一个按钮,一个标签和两个子(按钮单击和我创建的一个私人子)。在我的本地IIS上运行网站时(来自Visual Studio 2017的Web浏览器中的查看页面),该网站可以根据需要运行。

将站点发布到IIS服务器(v 8.5)时,收到以下消息: IIS Error Received

下面是在本地计算机IIS上成功运行的页面的副本:Successful on Local Machine IIS

这是网页的代码:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="adoptBooks.aspx.vb" Inherits="adoptBooks" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="form1" runat="server">
                <div>          
                    <asp:Button ID="tryMe" runat="server" Text = "try it out" />
                    <asp:TextBox ID="isbnNumber" runat="server"></asp:TextBox><br />
                    <br />
                    <asp:Label ID ="bookInfo" runat="server"></asp:Label>  
                </div>
            </form>
        </body>
    </html>

这是服务器端的代码:

    Partial Class adoptBooks
        Inherits System.Web.UI.Page
        Protected Sub tryMe_Click(sender As Object, e As System.EventArgs) Handles tryMe.Click
            dostuff(Me.isbnNumber.Text)
        End Sub

        Private Sub dostuff(passedISBNnumber)
            Dim resultHTML As String = String.Empty
            Try
                Dim service = New Google.Apis.Books.v1.BooksService(New BaseClientService.Initializer With {
                    .ApplicationName = "Discovery Sample",
                    .ApiKey = "my_key_is_here"
                })
                Dim reslut = service.Volumes.List(passedISBNnumber.ToString).Execute()
                resultHTML = resultHTML + "<table>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<img src=""" & reslut.Items.FirstOrDefault.VolumeInfo.ImageLinks.Thumbnail.ToString & """>"
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<strong>Book Title:&nbsp;&nbsp;</strong>" & reslut.Items.FirstOrDefault.VolumeInfo.Title
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<strong>Publisher:&nbsp;&nbsp;</strong>" & reslut.Items.FirstOrDefault.VolumeInfo.Publisher
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<strong>Date Published:&nbsp;&nbsp;</strong>" & reslut.Items.FirstOrDefault.VolumeInfo.PublishedDate
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<strong>Author(s):&nbsp;&nbsp;</strong>"
                Dim aths As String = String.Empty
                For Each author In reslut.Items.FirstOrDefault.VolumeInfo.Authors
                    aths = author & ", "
                Next
                resultHTML = resultHTML + aths.Substring(0, aths.Length - 2)
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                For Each indi In reslut.Items.FirstOrDefault.VolumeInfo.IndustryIdentifiers
                    resultHTML = resultHTML + "<strong>" & indi.Type & ":&nbsp;&nbsp;</strong>" & indi.Identifier & "<br>"
                Next
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "<tr><td>"
                resultHTML = resultHTML + "<strong>Description:&nbsp;&nbsp;</strong><br>" & reslut.Items.FirstOrDefault.VolumeInfo.Description
                resultHTML = resultHTML + "</td></tr>"
                resultHTML = resultHTML + "</table>"
                bookInfo.Text = resultHTML
            Catch ex1 As Google.GoogleApiException
                Response.Write(ex1.Message & "<br><br>")
            Catch ex As Exception
                Response.Write("There was an error processing this request.  Please check that the ISBN entered is valid and try again!")
            End Try
        End Sub
    End Class

我要导入以下内容(我知道我有很多需要的东西,这只是我的“播放页面解决方案”,所以不干净!):

System,System.Net,System.Runtime.Serialization,System.ServiceModel,System.IO,System.Security.Policy,Newtonsoft.Json,Newtonsoft.Json.Linq,System.Threading.Tasks,Google.Apis.Discovery .v1,Google.Apis.Discovery.v1.Data,Google.Apis.Discovery,Google.Apis.Services,Google.Apis.Books.v1.BooksService

下面是web.config文件:

    <?xml version="1.0" encoding="utf-8"?>
        <!--
        For more information on how to configure your ASP.NET application, please visit
        https://go.microsoft.com/fwlink/?LinkId=169433
        -->
        <configuration>
            <configSections>
                <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
            </configSections>
            <system.web>
                <compilation debug="false" strict="false" explicit="true" targetFramework="4.6.1" />
                <httpRuntime targetFramework="4.6.1" />
                <customErrors mode="Off" />
            </system.web>
        <system.codedom>
                <!--<compilers>
                    THIS SECTION REMOVED BECAUSE IT DOES NOT "PLAY NICE" WITH IIS (NO I HAVEN'T UPDATED IIS IN A WHILE...PROBABLY SHOULD DO THAT!)
                    <compiler language="c#;cs;csharp" extension=".cs"
                    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=ONE_TOKEN_HERE"
                    warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
                    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
                    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=ONE_TOKEN_HERE"
                    warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
                </compilers>-->
        </system.codedom>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="ONE_TOKEN_HERE" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http" publicKeyToken="ONE_TOKEN_HERE" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    </configuration>

是什么原因造成的?我发现的所有内容都与在IIS上运行API有关,但不与第三方API连接以及如何处理它。

0 个答案:

没有答案