Asked by:
Publsh/Deploying MVC5 on Windows Server getting 404 for an Action, but on Local it works great…

Question
-
User-544325736 posted
Hello everyone,
I have an MVC5 application and when I run it in Localhost it runs great no errors! When I publish it and deploy it on my server. (Windows Server 2016 and I tried AWS cloud) and put it on IIS I can get to my home page and my other links but when I run my ajax() and call an Action in my controller I get xxx.xxx.xx x.219/Parts/DoPartBookFunc?bookval=8 404 (Not Found) when I run localhost on the server I get Failed to load resource: the server responded with a status of 404 (Not Found) but when I debug the app locally it works. I been researching and trying a bunch of different things but so far no luck. Some I tried was @Url.action(“”,””), adding a ~ in front adding ../ in front making a global file and many other things. If someone knows how to fix this it would be hugely appreciated.
$("#PartBook").on("change", function () { var selectV = $(this).val(); var selectT = $(this).text(); $.ajax({ url: '/Parts/DoPartBookFunc', type: 'GET', dataType: 'json', data: { bookval: selectV }, //contentType: 'application/json; charset=utf-8', success: function (data) { //alert("s" + data.PartNextNumber);
Wednesday, July 10, 2019 9:22 PM
All replies
-
User1120430333 posted
That 404 not found is a catch 22, and most likely a DLL is missing causing the 404 not found . You should figure out how to remote debug on the Win 2k12 server
https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging?view=vs-2019
The other thing you can do is to publish the solution to your development machine to local IIS, I am not talking about IIS Express, see if the problem follows and try to debug it locally.
Thursday, July 11, 2019 1:29 AM -
User1520731567 posted
Hi ExceedingLife,
ExceedingLife
I been researching and trying a bunch of different things but so far no luck. Some I tried was @Url.action(“”,””), adding a ~ in front adding ../ in front making a global file and many other things.I work fine in my project with @Url.action(“”,””).
Actually,it hard to reproduce your issue because of different configuration environments.(maybe you use url-rewrite...)
Could your post web.config so that I can find differences.
Best Regards.
Yuki Tao
Thursday, July 11, 2019 8:07 AM -
User-544325736 posted
Here is my web config
I dont really understand why u need it..
<?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=301880 --> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <!-- set to false for publishing debug=false --> <compilation debug="true" targetFramework="4.6.1" /> <httpRuntime targetFramework="4.6.1" /> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" /> <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" /> </dependentAssembly> </assemblyBinding> </runtime> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 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=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> <connectionStrings> <add name="PartNumberEntities" connectionString="metadata=res://*/PartNumberModel.csdl|res://*/PartNumberModel.ssdl|res://*/PartNumberModel.msl;provider=System.Data.SqlClient;provider connection string="data source=xxxm;initial catalog=PartNumber;persist security info=True;user id=xxx;password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> <add name="PartNumberConnectionString" connectionString="Data Source=xxx;Initial Catalog=PartNumber;Persist Security Info=True;User ID=xxx;Password=xxx;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> </configuration>
Thursday, July 11, 2019 1:26 PM -
User753101303 posted
Hi,
Usually it happens when your app is published to https://site.com/app rather than to https://site.com
If this is the case the correct path is /app/Parts/DoPartBookFunc (if confirmed we'll see how to build a path that works regardless of the situation)
Thursday, July 11, 2019 2:27 PM -
User-544325736 posted
This is how i solved it
url: "@Url.Action("AjaxDescriptionSearch", "Parts")", and /* Newly Added */ routes.MapRoute( name: "AddNewControllerName", url: "AddNewControllerName/{action}/{id}", defaults: new { controller = "AddNewControllerName", action = "Index", id = UrlParameter.Optional } ); /* Old Route */ routes.MapRoute( name: "mass", url: "{action}/{id}", defaults: new { controller = "Parts", action = "Index", id = UrlParameter.Optional } );
Thursday, July 11, 2019 2:35 PM -
User753101303 posted
Great to see it is solved though it seems weird and I'm not sure to get which problem you solved.
If this is what I though just using url:"@Url.Action("DoPartBookFunc","Parts")", should be enough.
Not sure why you have now "AjaxDescriptionSearch" or "AddNewControllerName" (or this is not to shown real names ???)
Thursday, July 11, 2019 3:05 PM