Been using Visual Studio 2019 & ASP.Net. Got all my endpoints working during the development. When deployed on IIS, all my endpoints return 404. While looking at the logs, I get a "404 0 2" error.
I can browse to all pages fine, just the end points not working. I have tried adding various things to my Web.Config all with the same result.
Is a 2019 Server with the latest version of IIS.
Any help is appreciated. Guessing something is setup wrong on IIS?
The endpoints are done in using a controller, sample code below:
[Route("~/api/students/getyear/{yearid}")]
public async Task<ActionResult<IEnumerable<Student>>> GetYear(int yearid)
{
return await _context.Student.Where(x => x.yearid == yearid).ToListAsync();
}
Called by using
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
When debugging it, I can reach it from "https://localhost:5001/api/students/getyear/0" and when trying on my IIS using "intranet.domain.co.uk/studentnotices/api/students/getyear/0" I get the 404 error
I publish the code to the release folder and copy it to my IIS. Have also tried publishing directly to the IIS but same result
The win32-staus has already indicated that "The system cannot find the file specified."
So I think your IIS is trying to execute the URL from physical path.
It might because your static file handler is taking over the request instead of asp.net extensionless handler.
Please install IIS asp.net extension feature in turn windows features on or off. For .net core ,application, please ensure asp.net core web hosting bundle has been installed.
Related
I have an Web API project with .NET 5 (created directly from the template of visual studio Asp.NET Core Web API), it works just fine when debugging from Visual studio, tried to deploy it to IIS server, which has the Hosting Bundle of .NET 5 installed, the deployment apparently runs fine, but when I enter the url I have a 404. Have a separate MVC .NET 5 project, which I deploy in the same way and it runs perfectly fine.
Would like to know if someone can point me to the right direction, can't find what I'm missing here.
After searching and messing with Startup.cs file I notice that
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "api v1"));
Was inside the validation if(env.IsDevelopment()), but the api endpoints were working just fine, just that though that it doesn't work because I was unable to see the Swagger site, probably because you don't want to expose your api to everyone... feels like I miss a little explanation somewhere but all good now.
Faced the same issue. After configuring, when tried to browse 404 error came up.
The reason is, Swagger page will be configured in only for development environment as below(in Startup.cs).
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AppName v1"));
}
The APIs will be available if we type in the correct url.
If you still wants to view the Swagger file
Either change the code in startup.cs remove the check for
if (env.IsDevelopment())
Or In your web.config file set environment as Development.
If you have deployed a NET5 API to local IIS for development propose, you should set the environment to development using the web.config file
<aspNetCore processPath="dotnet" arguments=".\NewDealerWebAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore
You can solve your problem by following the steps on this site.
https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio
You didnt specify where you're pointing to swagger or directly to the api?
Additional things to check with OpenApi/Swagger/Swashbuckle/whatever the name is this week:
If you're going to https://yourAppUri/swagger/index.html
As noted in other replies, if you deploy to production, the environment may be different so the "if (env.IsDevelopment())..." is in your program.cs or startup.cs and your server has the "Production" or "Staging" value set, you'll get a 404 because swagger isn't found or generated because of that if statement.
There is a hierarchy to where the env vars are set if you're unsure. Basically its in this order: command line, environment variables, user secrets, appsettings.someEnvironment.json, then finally appsettings.json.
Verify that in your .csproj file it contains the following in the PropertyGroup tag (I had recently generated a new api project via the cli and the below was conveniently left out:
...
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
For internal APIs, I completely remove the if statement to always generate the swagger docs so end users can use it, but also force an api key so its semi locked down.
For hitting the api (since there's no controller code in your question):
Validate your url is correct, I'd copy the url after visual studio or rider starts up with and replace localhost with your server name/info and hit it with PostMan or something similar
Verify you dont have other bindings set in IIS, is the host environment using different ports to go to like: 8080.
Most other things would throw a 500 error I can think of...
I have managed to publish an MVC6 website to IIS, but it seems to be only serving the static files in wwwroot. As soon as I make a request to a MVC controller endpoint I get a 404.
What other steps do I need for the backend code to run? I see that in the web.config it is executing the web.cmd file in approot, but this doesn't seem to be running.
Edit Running the web.cmd directly - i.e. using the self-host ability - works fine on the server where the app is deployed.
I had a similar issue to this (404 on every page except for root) and while initially it looked like an IIS configuration issue or a problem with httpPlatformHandler, after running web.cmd manually I was able to find some issues with my connection string.
After fixing these issues I was able to run the site through IIS without any hassles.
I have an ASP.NET Web Application project that I am using to host a WCF Data Services (OData) project.
I went and changed the url from:
http://localhost/MyProject
to
http://localhost/v1/MyProject
after I did that I created a Virtual Directory for the new project URL.
Now when I run I get this error:
Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information.
I clicked help but it was no help (was IIS 6 level instructions, I have IIS 7). I did some googling and it was all fairly generic responses.
How can I get this working again? (Aside from revert to my old Url. Reverting works but I changed it for a very good reason.)
Your virtual directory need to point to the same scr directory you were originally debugging against.
Also, make sure the virtual directory is configured for Windows Authentication, which is required for debugging.
I had to go to my website in IIS and add a folder under it called v1. After I did that it all worked perfectly.
I'm getting the following error after migrating an app built on II6 to IIS 7.5
Module IIS Web Core Notification
MapRequestHandler Handler StaticFile
Error Code 0x80070002
On the IIS 7.5 side, I have a wildcard script map setup to:
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
The application pool is setup to use classic mode and .Net 2.
The URL I am working with would looking something like this:
http://fb.domain.com/ryanqaaw/tab/
The wildcard map would handle the /ryanqaaw/tab/ as those folders to not exist in the root.
Any help or tips would be GREATLY appreciated!
EDIT:
Adding Failed Request Tracing shows this:
ModuleName="IIS Web Core", Notification="MAP_REQUEST_HANDLER", HttpStatus="404", HttpReason="Not Found", HttpSubStatus="0", ErrorCode="The system cannot find the file specified.
(0x80070002)", ConfigExceptionInfo=""
But I am not too sure what to make of it...
In IIS 7.5 the configuration is far more simple, almost no configuration required.
What I suggest is, create a new Web application project and make it run in IIS 7.5 and then change your application's config file to mirror the new one.
Instead of your wildcard handler use an integrated pipeline for your apppool and all should be fine.
Start IIS Manager and click on the server name. Double click on the option [ISAPI and CGI restrictions]. See if ASP.net v2.0 is enabled or not.
You need to move the wildcard mapping in the Handler Mappings list so that it comes before the StaticFile handler (clicking on "View Ordered List..." link in the actions pane and use the Move Up/Down options)
I'm trying to setup the MVC development enviroment on my laptop. I'm running WinXP Pro with IIS 5.1
I got the environment setup with the sample MVC application that come with beta. I can only get to the home page. when i try to open About us page. i run into the page can not be found error. Is it the routing not set in the Global.asax?
Your issue is that IIS 5/6 don't play nice with routes without extensions, the home page is resolving because its pointing to default.aspx,
In a nutshell, do this:
If *.mvc extension is not registered to the hosting , it will give 404 exception. The working way of hosting MVC apps in that case is to modify global.asax routing caluse in the following way.
routes.Add(new Route("{controller}.mvc.aspx/{action}",
new MvcRouteHandler())
{ Defaults = new RouteValueDictionary (new{ controller = "YourController"} ) });
In this way all your controller request will end up in *.mvc.aspx, which is recognized by your hosting. And as the MVC dlls are copied into your local bin , no special setttings need to be done for it.
See this question for lots of good information:
ASP.NET MVC and IIS 5
You may go to your IIS site's properties, tab "Home directory", press "Configuration...", select ".aspx", press "Insert...", Type "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll", uncheck check box and press "Ok". This heplped me.
Url rewriting can help you to solve the problem. I've implemented solution allowing to deploy MVC application at any IIS version even when virtual hosting is used.
http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx