API setup missing something? - asp.net

I am setting up a web api for the first time and I have another project for reference. It is a .NET framework project that will have a React frontend. I am running it using Visual Studio and IIS Express.
I have no build errors when I start the api project. It has swagger added so I can test database calls, so I know the api itself is working. But I am missing adding something as I am looking to add more security to it.
I am trying to verify authentication and I want to use integrated Windows authentication. When I set a break point, the user in the HttpContext.Current is never set and is never authenticated, so I can't add any authorization filters.
I went back to just the basic empty api project that has the frontend web pages removed to see if I removed something and it shows the same issue. So I either removed it again or I am actually missing adding something.
I am not sure where to look for what is missing, so any pointers would be appreciated.
The left browser is what I am expecting and the right browser is what I am seeing.
I don't need the directory browse turned on, so seeing a 403.14 - Forbidden is fine. But I am clearly missing something to get to that point. Is there a better way to figure out which resource/dependency is causing this error?
I can also see the working version requested url is what I am expecting, but the other is just a /.
Is there a way to resolve that if this is the error?
I can add code snippets if needed, but I haven't yet as I am not sure where the issue is.

I ended up finding the answer using blank test web apis to see what I may have left in that wasn't needed. The project was set up using this option:
After removing the views, etc., to make it strictly an api project. I started removing references (and clearing the associated errors) and seeing what happened with the build after each change.
Under the App_Start folder, there were some additional files that weren't present in the project I had for comparison - FilterConfig, and RouteConfig - which were also called in the Global.asax.
I removed the call in Global.asax for all three and I was able to see the expected http error page.

I dont have enough reputation for a comment, but you got 404 error, which, as you know, means there is nothing on that url. So check the route config and startup.cs Edit: I am on the phone so I didnt saw you already solved it. Good :)

Related

Azure - Uploaded MVC Project returns 404

Using Visual Studio 2019 I tried to Publish the MVC Project I've been working on. It goes well, but the default route returns a 404 Not Found. Other routes for login/register load the correct html content. This all works well on my localhost. I've been searching around but can only find things relating to Angular etc.
The index page loads content from a database, which I haven't set-up yet if that causes any issues?
Any help is appreciated as I'm boggled.
Issue solved. For anyone wondering in the future, if the page reads content from a database make sure the Migrations are applied and the database is exactly how it is on your local machine (This was my issue anyway).

2sxc: 404 Error after adding App module on the page. API is missing?

I have a problem when placing an App module(v 8.4.8) on a page. When I placed an App module on a page I got a pop up saying "Had an error talking to the server (status 404). if you are an advanced user you can learn more about what went wrong - discover how on 2sxc.org/help?tag=debug".
This error happens on whatever action I try to do: trying to add and app, refresh page etc.
I checked a communication to the server using Firebug and seems that one of APIs are missing:
~/desktopmodules/2sxc/api/view/Module/GetSelectableApps
Referer: ~/desktopmodules/tosic_sexycontent/dist/dnn/ui.html?sxcver=8.4.8.19191
Did I missed something? Should I make some configuration after SexyContent module install (v 8.4.8)?
I just checked a video by Daniel Mettler where he showed how to install a module and seems that process is simple. Nothing to worry about.
Does anybody has any idea what might went wrong here?
The same actually happens when I install and Content module: Error about missing APIs:
~/desktopmodules/2sxc/api/view/Module/GetSelectableContentTypes
~/desktopmodules/2sxc/api/view/Module/GetSelectableTemplates
Thanks a lot for your time
My best guess is that it's an issue with the dnn domain/path configuration. So basically my guess is that
you have multiple domains, and if this is configured incorrectly, the paths in the js-calls won't fully match the original one
you have sub-portal (with paths like /products/) or something, and this isn't configured correctly in dnn
languages in portal-paths are causing similar issues.
So please compare EXACTLY the full base path and see if that's the issue.

Resource Not Found - 404

So, I've copied a few methods from one controller to another, moved the respective views into the correct view folder and tried to debug my project..
After trying to navigate to one of the newly copied methods and views I get hit with this lovely error.
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /subscriber/addphonenumber
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.57.0
Now, I've double and triple checked that the views are in the right folder, even deleted them, went to the controller actions, right click -> add view and copied the view code over and still no joy.
The controller actions are there, the views are there, what gives?
I've tried cleaning the project, the solution, closing VS and restarting and still... nothing.
Also, when debugging, my breakpoints are never getting hit on the newly copied methods... Not sure what is going on there.
Note: I have NOT made any changes whatsoever to any of the routing configuration, I simply copied the ChangePassword, AddPhoneNumber and VerifyPhoneNumber actions/views from the Manage Controller and Views folder to my Subscriber Controller. These methods and views worked fine before I moved them.
Questions:
Why is Visual Studio not hitting my breakpoints
Why are these views and controller actions not being recognized?
EDIT
I resolved this issue, check below to see my answer.
The solution in my case ended up being this.
I had an area in my project with the same name as a controller in the root controllers folder, that was causing a routing issue and in turn the 404 error. The routing issue prevented my actions from being found, hence the breakpoints not being hit. After removing or renaming the area, everything seems to be working fine.
Project Structure
areas/subscriber - empty
controllers/subscriber
views/subscriber/index
views/subscriber/addphonenumber

Asp.Net System.Web.Routing won't route URL unless .aspx in on the end

I have a weird problem with routing. I have an existing website that I am trying to add this to. It works, but only if .aspx is on the end of the URL. If I remove the .aspx, it gives me an error: "The resource cannot be found." I created a quick test website and copied the code over to it, it works just fine. The code between the 2 are identical. Both are running on the VS 2008 web server. I just don't get it. Any ideas?
Thanks,
Vincent
Okay, I found the problem. I don't understand why this caused the problem, but if there is a period (.) anywhere in the URL, it errors.
I had this: http://localhost:49463/site.dev/products/keylessentrykits
When I changed it to: http://localhost:49463/sitedev/products/keylessentrykits, removing the period between site and dev, it worked fine.
Anyone have a clue to why this is? Is it a bug?
Also, I should have said something before, but this is not an MVC app.
I think you need to set the ISAPI dll to handle all files (i.e. add a wildcard). It's working because it's set to handle .aspx.
Thank you kindly for finding the solution and posting it. I have been suffering from the exact same issue and have been trying to get it resolved for days now!
My solution contains several projects: web, business logic, data access, etc. My web project was called "SystemName.WebForms" and when I was compiling and running from Visual Studio's debugging environment only routes that contained a period were being routed properly. Once I renamed my web project to "SystemName_WebForms" all of the routes were processed properly. I highly suspect this is a bug that you discovered.
Many thanks for finding the workaround and having the generosity to post it!
MomentSurfer

Why would an aspx file return 404 ("The page cannot be found")

Why when I access an aspx (e.g., http://www.example.com/foo.aspx - not the real site) through IE6 would I get a 404 Error (i.e., "The page cannot be found") in IIS6
I've got scripts enabled for the website and I've tried with executables enabled as well.
Here is the full error:
The page cannot be found
The page you are looking for might have been removed, had its name changed, or
is temporarily unavailable.
------------------------------------------------------------------------------
Please try the following:
Make sure that the Web site address displayed in the address bar of your
browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site
administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)
------------------------------------------------------------------------------
Technical Information (for support personnel)
Go to Microsoft Product Support Services and perform a title search for the
words HTTP and 404.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for
topics titled Web Site Setup, Common Administrative Tasks, and About Custom
Error Messages.
I can get to Default.htm in the same directory, so I know the path is right. I've opened it up to everyone (temporarily) so I know the permissions are right.
It could be a lot of things. I had this issue today because .NET had not been re-initialized after installing IIS (aspnet_regiis -i -enable or equivalent).
Check that the anonymous user under which the site runs has read access to the file foo.aspx.
IIS6 and later uses a 404 response, thereby not letting an attacker know whether such a file even exists.
I just happened to find another culprit for this issue. My foo.aspx page referenced a particular master page that had a <%# Register %> directive to a user control that did not exist. Removing the reference to the non-existent user control caused my foo.aspx to load instead of 404.
I found a solution here.
The real catch was using this:
Response.TrySkipIisCustomErrors = true;
The site is pointing to a different directory where the page is not.
It could be permissions, however I would think you would get an access error instead.
I'm assuming you are running IIS.
Check that www.example.com is going to the site that you think it is.
If you are hosting multiple sites on the same IP using host headers you may want to double check the name you are using is going to the site you think it is.
Ray and Joe probably have it. In order to serve any file type, IIS has to have a mapping for it. Aspx files require that they be mapped to the AspNet ISAPI dll, which the .Net installation normally takes care of. If you install IIS after .Net (and I'm sure there are other situations), you have to initiate this yourself by running aspnet_regiis.
ALTERNATE SOLUTION (same error perhaps different cause).
I had installed Visual Studio 2008 Pro without SQL Express it, and it caused this same error. Reinstallation of VS2008 with sql express included seemed to have corrected the problem, or perhaps the install took other actions. I did try to register ASP.net numerous times prior but no luck however it is definitely the most probable cause Just posting my experience for those pulling their hair as I was..
Thanks
If you register the .NET 4 version of IIS, you may find it's grabbed the registration of the aspx extension. If ASP.NET v4 is prohibited then 404 will be returned
I had this issue where some customers were reporting the 404.0 and some didn't have the problem at all(same page). I was able to navigate to any of the pages with no problems from my machine. Some customers would refresh and it would go away. I am using .Net 4.5.2 and IIS 7.5.
Looking at the IIS log file I would see:
sc-status sc-substatus sc-win32-status
404 0 2
sc-status.sc-substatus: 404.0 - Not Found
sc-win32-status: 2 - ERROR_FILE_NOT_FOUND
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
https://en.wikipedia.org/wiki/HTTP_404
I found the problem was I had deployed a new version of the website in which the old version of the website had RouteConfig.cs/FriendlyUrlSetting setup by creating a project using the web forms template. The new version was created using an empty template. So obvious to me now.. no URL routing. Customers had a cache issue with certain pages on their machine(no .aspx extension) and having them clear browser data ultimately fixed the problem.
I got this issue when I tried using a different drive to host my apps. I ended up moving them to the wwwroot folder because it was working there and I did not have to time figure out why it is not working on the E:\ drive.
I had bin\roslyn compiler missing. Adding that all worked fine.
Check for double quote errors. I started getting a 404 on a single page because I accidentally had this:
<asp:TemplateField HeaderText="ImageURL"">
instead of this:
<asp:TemplateField HeaderText="ImageURL">
For an aspx page, error 404 can be quite misleading! I have seen all the answers and they presuppose assuming various issues with the file, page, path, etc. but the simplest issues is the fact that if there is an error in your asp page (i.e bad format, improper usage of control, etc. asp will think the page does not exist and will post a 404 when in all actuality, it is easy to ascertain if there is a bad format by simply clicking on design mode. If the page does not render no need to do anything else but look at what is causing the render error, fix and viola'! Your page shows since it was never missing or can't be found, but it simple did not know how to display! Too often people go looking for the wrong solutions and waste so much time! Hope this helps somone. :-)

Resources