.Net MVC 3 403.14 error - c#

I'm creating an asp.net MVC3 demo application. I have attached the application with this thread. I'm facing a HTTP Error 403.14 - Forbidden issue when trying to run the application. The issue occurs only in a specific scenario. i.e. in the RegisterRoutes method in the global.asax
has only the below code then the issue occurs.
routes.MapRoute(
"Process1", // Route name
"Process/List" // URL with parameters
);
If we have the above code with default route the application works fine without any issues. The issue occurs when i have this particular code alone in the register routes method.
I tried the solutions given in this link but it did not work.
I assume the issue with that code. If yes then please let me know what causes the issue. I use windows 8.1 & the iis is 8.5.
The code can be found here

You have removed the default route and defined the following route:
routes.MapRoute(
"Process1", // Route name
"Process/List" // URL with parameters
);
In this declaration it is not clear which controller and which action should be
executed. You should explicitly state them:
routes.MapRoute(
"Process1", // Route name
"Process/List", // URL with parameters
new { controller = "MyController", action = "MyAction" }
);
and then make sure that you are making the request to the proper url that you have defined:
http://localhost:1619/Process/List
because you don't have any route configured that is capable of handling the http://localhost:1619/ request that you seem to have made in your screenshot.
Of course having such route is completely constraining. The only controller action you could ever have in your MVC application is the one defined as such in the route config. This is fine in a SPA application where you have a single entry point serving the SPA and a separate ASP.NET Web API but in a real ASP.NET MVC application with multiple controllers and actions it is not going to work. So you probably want to keep the default route in this case and do not experiment in this area.

You must have a default root in your global.asax file to make it work. add one default and then you can add this route.

Related

Running Angular 2/4 Route instead of .net Core route

in my Angular Module I have the following Route:
{ path: "something/:id", component: SomeComponent }
which runs fine when using "routerLinks" frontend, but as soon as I manually write the ID in the URL and press Enter, It runs the C# backend method instead and ignores the angular route.
[HttpGet("{myid:guid}")]
The backend method returns Json as it should but I cant get my Angular route to display my component, seeing I go straight to the Controller.
So my question is: How do I tell my application to run my frontend route instead of my backend route, or work my way around this problem when manually writing the id in the url?
Any help would be greatly appreciated.
I realise this isnt strictly answering your question, but unless you have a specific requirement to handle them on similar routes, isnt it simpler to serve your API on a clearly distinct route using a subdomain or specific base url fragment?
E.g. front end routes go on:
www.example.com
API routes go on:
www.api.example.com or www.example.com/api/
Note that if you cant use the subdomain option, you'll need to configure URL rewrites in your web.config to route between your API and front end.
Have you tried configuring your startup.cs? On the configure method try:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});

ASP.NET MVC Attribute routing: NullReferenceException on specific controller

I'm working on a MVC project with several controllers that used to route with default RouteConfig, i.e. "{controller}/{action}/{id}".
Now the project leader wants to implement custom routes. I decided to use Attribute Routing because I used that on another small project which only had one controller.
I prefixed the HomeController and the AccountController and all the actions have Routing attributes now. This is working fine for Home and Account Controller. But I have another controller which I called PaymentController. Somehow, this controller cannot be reached with attribute routing. I tried prefixing and not prefixing the whole controller. What I think is the most strange thing is that it's throwing a NullReferenceException in System.Web.Mvc.Routing.DirectRouteCandidate.CreateAmbiguousMatchList.
I used the routes.MapMvcAttributeRoutes(); in RegisterRoutes, obviously, since the routing for the other two controllers works fine. Before adding the attributes in my payment controller, the default routing worked fine as well.
Do I have to configure anything else, did I forget something? Has anyone ever experienced a NullReferenceException in AttributeRouting? Is there a way to debug routing? I tried glimpse but since the routing is not successful it doesn't show anything.
Thanks in advance for your help.
edit:
As stated above, the controller is reached with default routing, so no nulref in the controller. I think the exception happens in
'System.Web.Mvc.Routing.DirectRouteCandidate.SelectBestCandidate'

Host WebApi and C# site under the same domain

I have a website made in C# (http://my.site/), and now i have a Web API project that i want to merge to that domain and listen on http://my.site/api. They are 2 separate projects in VS2013.
I tried uploading Web API to /api/ subfolder in the server and map a MVC route to it (WebApi route in WebApiConfig.cs still routeTemplate: "api/{controller}/{id}"), expecting the default (Home) MVC controller to respond in /api/. The MVC route (in WebAPI's MVC routing):
routes.MapRoute(
name: "Default",
url: "{controller}", //Also api/{controller}
defaults: new { controller = "Home", action = "Get", id = UrlParameter.Optional }
);
But i get "Server Error 404" when accessing http://my.site/api/ / http://my.site/api/home etc. I don't understand the nature of this error (most likely settings in the C# website in root folder), but one would think IIS would serve the default app inside the /api/ folder.
So i want to know if adding WebApiConfig.Register(GlobalConfiguration.Configuration); to Global.asax (Application_Start()) and adding WebApiConfig.cs to App_Start folder of the C# project (and using the respective namespaces) will solve the issue. This seem too simple to be true so i doubt it will work, so i need someone to point me in the correct direction, or i will commit the sin of going back to asmx.
If not, how can i have C# website and a WebAPI on same domain?
You are wanting to run two separate dlls (each with their own routing rules) within the same bin folder on your server. That could definitely cause some conflicts in routing on your site. A proper way to do this would be to host your api project on a separate server and use a sub-domain, such as http://api.my.site/. That way you ensure that your C# site (http://my.site/)would have access to the api (http://api.my.site/). And your dlls, including routing rules, would remain separate.

MVC RouteConfig

I've set up an MVC project, it works perfectly. But I upgraded with a new controller, added some new views, nothing special... The web page works almost perfect when online except that it can't find my new views online.
I really don't know why, because it works in all debug modes in localhost on my machine, but not when published, I did publish the entire solution.
I've also noticed that I can't add new pages to my working home-controller either, I can only edit the ones that I have.
I checked RouteConfig and there are only the default basic settings
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
I've created a new controller called Questionnaires, do I have to add this to RouteConfig to make it run online?
Browser address:
www.<address>.com/home/OneView
But with the new Views I want this for the new pages:
www.<address>.com/Questionnaires/Mixer
When browsing to the address I receive this 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: /Questionnaires/Mixers
You said it can't find your views, but routing isn't concerned with views. It's concerned with mapping requests to a controller and action method. The action method is what returns the view. If you created a new controller called QuestionnairesController, then you should be able to access it at /Questionnaires. And since that URL doesn't specify an action method, it will by default (because of your configured route defaults) look for an action method named Index.
If you want to access the Mixer action method in the QuestionnairesControllers at /Questionnaires/Mixer, that should work fine based on the routing you showed us.
When you do return View(); in your Mixer action method, it will by default look for a view at ~/Views/Questionnaires/Mixer.csthml (among several other locations, but that's where you most commonly put it).
This is a bit embarrassing, but I did not notice that i published my project in Debug mode, set to Release solved the problems. Never missed this before.
Sorry about all this, have mercy...

MVC custom route question: Route one level higher?

I have a web application that I'm using a custom route to route http://domain/MyMVCSite/MyPage.ASP to route to a controller/action of my choosing.
I'm not TOO familiar with custom routing, but as it stands, this is my custom route:
routes.MapRoute(
"Page",
"MyPage.ASP",
new { controller = "KTASP", action = "KTASP", id = "" }
);
As I said, this routes:
http://{domain}/MyMVCSite/MyPage.ASP
I would like for it to route:
http://{domain}/MyPage.ASP
Is this possible? How would I tweak the custom route?
My MVC site is being deployed as a virtual directory of a website on IIS6.
This isn't possible without IIS configuration to rewrite the requests for "http://{domain}/MyPage.ASP" to go to your virtual directory.
Currently, your web application will never get considered, because that page is not within the virtual directory it is mapped to in IIS. You need to either have routes (and a web app) at the root of the web site, or use URL rewriting to forward it to your vdir.

Categories

Resources