我想要部署我在Web应用程序中构建的API,这不是MVC,所以API控制器代码在App_Code中,Global.asax.cs有路由代码:
RouteTable.Routes.MapHttpRoute(
//GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "MyAPI",
routeTemplate: "api/{controller}/{pakackagename}/{departure}",
defaults: new
{
pakackagename = System.Web.Http.RouteParameter.Optional,
departure = System.Web.Http.RouteParameter.Optional
}
);
此代码位于Global.asax.cs中的Application start中 在web.config中我有以下设置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<!--MITSU-->
<!--add name="ReservationConnectionString" connectionString="Data Source=xxx.xxx.xx.xxx;Initial Catalog=xxx;Integrated Security=False; User ID=xxxxx; Password=xxxxxx" providerName="System.Data.SqlClient" />-->
<!--BLUE-->
<!--<add name="ReservationConnectionString" connectionString="Data Source=xxx.xxx.xx.xx;Initial Catalog=xxxx;Integrated Security=False; User ID=xxxx; Password=xxxx" providerName="System.Data.SqlClient" />-->
<!--LOCAL-->
<add name="ReservationConnectionString" connectionString="Data Source=localhost;Initial Catalog=xxxx;Integrated Security=False; User ID=xxxxx; Password=xxxxx" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.1" />
</system.Web>
-->
<system.web>
<trust level="Full" />
</system.web>
<system.web>
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
<machineKey validationKey="xxxxx" decryptionKey="xxxxxx" validation="SHA1" />
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.5" batch="false">
<assemblies>
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<!--SAMPLE-->
<sessionState mode="InProc" cookieless="true" timeout="30" />
<!--<sessionState mode="StateServer" cookieless="false" timeout="20"/>-->
<!--<sessionState mode="SQLServer" sqlConnectionString="data source=127.0.0.1; integrated security=true;" cookieless="false" timeout="20"/>-->
<!--MITSU-->
<!--<sessionState mode="SQLServer" sqlConnectionString="Data Source=xxx.xxx.xx.xxx; Integrated Security=false; User ID=xxxx; Password=xxxxx;" cookieless="false" timeout="20"/>-->
<!--LOCAL-->
<!--<sessionState mode="SQLServer" sqlConnectionString="Data Source=xxxx; Integrated Security=false; User ID=xxxx; Password=xxxxx;" cookieless="false" timeout="20"/>-->
<httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<appSettings>
<add key="R_PT_P" value="show=false;Description=Region-Product Type-Product" />
<add key="R_P" value="show=false;Description=Region-Product" />
<add key="P" value="show=false;Description=Product" />
<add key="PT_R_P" value="show=true;Description=Product Type-Region-Product" />
<add key="SMTPServer" value="xxxxxx.in"/>
<add key="SMTPUserId" value="xxxx@xxxxxx.in" />
<add key="SMTPPwd" value="xxxxxx"/>
<add key="LockDuration" value="10"/>
<!--This value is in minutes-->
<!--<add key="username" value="xxxx" />
<add key="password" value="xxxx" />
<add key="secret" value="xxxx" />-->
<!--<add key="mercid" value="xxxx" />-->
<!--Testing
<add key="mercid" value="xxxxx" />
<add key="username" value="xxxx" />
<add key="password" value="xxxx" />
<add key="secret" value="xxxxx" />-->
<!--Production-->
<add key="cName" value="xxxxxx" />
<add key="cAddress" value="xxxxxx" />
<add key="cEmail" value="xxxxx@xxxxxx.in" />
<add key="cPhoneNo" value="+91xxxxxxx" />
<add key="cMobile" value="+91xxxxxxxx" />
<add key="cLogo" value="http://xxxxxxxxxx.in/xxxxxx/xxxxx/xxxxxxxx.xxxx" />
<add key="ccEmail" value="xxxxxx@xxxxxxxx.com" />
<add key="username" value="xxxx" />
<add key="password" value="xxxxx" />
<add key="secret" value="xxxxx" />
<add key="mercid" value="xxxxx" />
<add key="FtpUid" value="xxxxx"/>
<add key="FtpPwd" value="xxxxxxx"/>
<add key="EncryptionAllowed" value="true" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
问题在于打开服务器上的URL,当我打开http://localhost:xxxx/api/Values/xxxx/xxxx时,它会工作并返回XML,但是当我使用http://example.com/api/Values/xxxx/xxxx/时,它说404找不到。
我在互联网上尝试了一切,但仍然没有帮助。
答案 0 :(得分:0)
我创建了新的WebAPI项目并部署在子域上。它的方式要好得多。