I have a Web API project in MVC 4 but cannot find the URL to my web service. Rather than MVC, I am actually just using the C (controller) as I'm not returning a view and my model is located in an external project.
I'm using the default route, which is api/{controller}/{id}. The name of my controller is RESTController (I know, probably wasn't the best name) and is located at ~/Controllers/RESTController.cs
Based on naming convention, it seems that my web service should be located at localhost:port/api/REST but I'm just getting a 404 resource cannot be found error (no XML representation of the object returned or anything). Is this the expected behavior without a view?
The funny thing is that I also have a SOAP API in an external project that is actually just returning the REST API result and it works as it should. Doing unit tests on my methods passes... I just can't access it from a browser. I've tried every url imaginable.
Basically...
Would there a way to debug this? (ie. Turning on ASP.NET directory listing)
Does not having a view effect what is shown in the browser?
Shouldn't the browser return an XML file representing the object?
Am I missing something obvious?
Nevermind, I'm a moron. I found the problem... At some point I accidentally drag and dropped (drug and dropped past tense?) my Global.asax file into my Views folder... therefore my routes were not getting registered.
Working as intended now.
Related
I am not able to run any other controller in the default React app for .NET Core 6.0. Has anyone figured this out? I believe I saw a quick message on the terminal about the weatherforecast route being in the SPA proxy.
Whenever I try to go to any other route for a controller it redirects to the fallback page. I have routing setup with default settings. Just seems an odd behavior.
It's obviously a proxy issue because if I run the controller from the IIS port 7132 instead of the 44402 (spa server), I am able to retrieve the json response. There's quite a long readme file in here I can plod through but maybe someone has a better solution.
Update: I found the solution, well there were several, from setting CORS policies on the server side, etc. The easiest way was to do it "pre-flight". I found a handy file called setupProxy.js (who knew lol), where I was able to set an array of end points to proxy. And this had the /weatherforecast endpoint already specified. So now it all works! I guess I answered my own question.
const context = [
"/weatherforecast","/account"
];
Right now I have it at the bottom of the _Layout.cshtml layout page that is used by every other page. The problem I'm having is that pages under the Identity area throw errors in the console when navigating to Identity pages:
POST https://localhost:5001/Identity/Account/_blazor/negotiate 404
and
blazor.server.js:1 Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.
These errors make me think I'm doing something wrong with how I enable Blazor Server in my RazorPages app.
So I'm wondering, should I only have the blazor.server.js scripts on pages that are actually using Blazor? Is there a way to make it available to Areas that putting it in the Layout seems to not do?
I believe this post answers my question:
How do I use blazor server-side inside a razor component library using areas?
By default, the SignalR service uses a relative path and was unable to find the _blazor/negotiate endpoint within an Area. The suggested code change in _Layout will make it use absolute paths and normalize to /_blazor/negotiate wherever you are in the page structure.
I know this is late but incase it help others.
I got this error when I was trying to add blazor to my existing app.
I added:
<base href="~/" />
at the end of the head tag of the _layout.cshtml file found in the shared folder.
enter image description here
I'm using mvc4 and .Net 4.5 in my project with SSL. Now, on localhost and even on server, the login page gets redirect a bunch of times and then loads without and css on page. In browser debugger I get error as:
Uncaught SyntaxError: Unexpected token <http://localhost:55248/Account/Login? ReturnUrl=%2fbundles%2fjqueryval%3fv%3dWrBNyT_GYLXAZ7iWD7vDdFccq24m7v_9MPi3rcQ8FO01&v=WrBNyT_GYLXAZ7iWD7vDdFccq24m7v_9MPi3rcQ8FO01...
I'm using bundling and code snippet as below.
bundles.Add(new ScriptBundle("~/bundles/BaseJs")
.Include("~/Scripts/jquery-{version}.js")
.Include("~/Scripts/jqueryui/jquery-ui.js")
.Include("~/Scripts/bootstrap.js"));
The syntax error is from the error page being loaded as JavaScript (when it's obviously not JavaScript). It's a red herring. The true problem is that your JavaScript file is needing authorization in the first place.
Typically, this wouldn't be an issue. By default, anything with an extension (.js, for example) is ignored by MVC and handled directly by IIS. Worst case scenario, there, IIS doesn't have permission to read the file, and you end up with a 403 Forbidden. It would end there, as an IIS-level 403 would not trigger a login page redirect, mostly because, again, MVC is not involved.
However, if you've bungled around the with default setup, such that MVC is now handling all requests, even for static files. Then, the action that's being triggered to handle the request to your JavaScript file is requiring authorization, and therefore is redirecting to the login page. So find out what action is being hit and either remove the requirement for it to be authorized or have the right action serve the file. Or, ideally, leave things as they should be and let IIS do what IIS does best and serve the static files.
EDIT
I wasn't paying attention to the fact that bundles are rendered without a file extension. However, the steps to correct the issue are largely the same. Something is mostly likely off with your routing, and the request for the bundle is actually being caught by one of your actions, particularly one that requires authorization. Look out for catch-all routes and make sure that you're not using a route like "bundles" anywhere in your RouteConfig.cs or any of your Route attributes, if you're using attribute routing.
First try to include your bundles like that :
.Include( "~/Scripts/jquery-{version}.js",
"~/Scripts/jqueryui/jquery-ui.js",
"~/Scripts/bootstrap.js"
);
Include takes string[] as parameter and you don't need to call include for each row. Then you should debug your bundles to see which js is giving the error.
Try to comment out rows 1 by 1 to see what would be the result. The problem is definatelly in your bundles, I also had these kind of errors. If you can provide more code - > snippet from the view, of the css loading and bundles and stuff like that I would be able to help you more.
I am trying to add some custom functionality to ElmahR dashboard page and having some issues. I have started a new project, added ElmahR dashboard NuGet package. Configured all source applications and it is all working fine as expected.
Now I want to add some custom functionality to the dashboard page. As part of this I needed to add some UI to the dashboard page, a new Hub, JavaScript etc. The custom functionality is not related Error Logging. It is completely different. It is something we would like it to add to the dashboard page. I have added new Hub, JavaScript, HTML markups but it doesn't work as expected.
I ran into the following issues:
When i try to access /signalr/hubs, I get 404 Not found error. I searched online for this error and it usually happens if you haven't configured the Hub route. I tried to add RouteTable.Routes.MapHubs() in global.asax file. However it says that A route named 'signalr.hubs' is already in the route collection. Makes sense because I am using ElmahR and because it relies on SingalR, it would have already added it to the route collection. So what is the path to /singalr/hubs in ElmahR application? When using signalR in your standard asp.net application, the usual path to hubs is /signalr/hubs but what path is it when using ElmahR?
I am getting JavaScript error "Uncaught TypeError: Cannot read property 'client' of undefined" at the line where I am trying to access hub.client. I guess it is failing because it is not able to find the new hub that i added.
Everything works fine if I copy the hub, associated JavaScript and HTML to a different ASP.NET MVC project. For some reasons it does not work with the Project that uses ElmahR. I know there is nothing wrong with the code in Hub and JavaScript as it works fine with a standard ASP.NET MVC project. Basically all I want to do is to add a singalR hub to a project that uses ElmahR. Also I can't seem to figure out the URL path to Hubs in an application that uses ElmahR. Usually the path is /signalr/hubs
UPDATE:
After further investigation, I figured the path to hubs in ElmahR dashboard application. It is /signalr101/hubs. However when requesting this, it errors: "Uncaught Error: SignalR: JavaScript Hub Proxy generation has been disabled". It appears that ElmahR would have disabled JavaScript proxies, probably by setting DisableJavaScriptProxies property of the application's IConfigurationManager to true (https://github.com/SignalR/SignalR/pull/1222). I think because of that I am getting "Uncaught TypeError: Cannot read property 'client' of undefined in my JavaScript at the line where it is trying to access hub.client. If the JavaScript proxy is disabled, then is there any extra work I have to do in my JavaScript and Hub so that I don't get this JavaScript error.
Just wondering if it's possible to get Elmah to log 404s that aren't picked up by the ASP.NET framework - i.e. the 404s that IIS spots and replies to.
Presumably this would involve some kind of entry in IIS -> web site properties -> Custom Errors tab.
Can't find any reference on how to do this.
Non-ASP.NET mapped extensions (e.g. static content, classic ASP, etc) will never hit the ASP.NET request pipeline so ELMAH will never know about 404 Not Found's generated by IIS6. You'd need to create a wild card extension mapping to aspnet_isapi.dll for this to be possible (or just specific extensions).