Asp.Net MVC route exception - asp.net-mvc

I am using MVC to develop my website. I am getting the following errors.
URL:http://www.abc.com/robots.txt
1. The controller for path '/robots.txt' was not found or does not implement IController.
URL:http://www.abc.com/blogs/post/whats-new-in-mvc
2. The controller for path '/blogs/post/whats-new-in-mvc' was not found or does not implement IController..
But i dont have the above mentioned url in my website. How the above url are generated? Can you please let me know the solution to fix the above issue?

The first one is used by search engines to index your website. It's a good practice to have a robots.txt file to your application. So you could add this file to the root of your site. As far as the second url is concerned, I have strictly no idea who is querying it. Maybe somewhere inside your site you have a link to this url?
But if you don't want to use this file you could exclude it from routing:
routes.IgnoreRoute("robots.txt");
Now when a search engine sends a request to this file he will also get a 404 but the request won't be routed through the MVC pipeline.

Related

ASP Classic - How to set up Permalinks. URL rewrite?

We have a web project which we are working on (Custom CMS). Have a url example http://www.test.com/page.asp?PID=191
Is there not an way to change this url into something like http://www.test.com/product-title/
Any help would greatly be appreciated.
An old method of doing this was to use custom error handling. Using a 404 custom error handling page you can trap a request to http://www.test.com/product-title/ pull it apart and build the request to the resource in this case http://www.test.com/page.asp?PID=191.
There are various ways of doing this from storing the values in a database so you can lookup your friendly address against it's equivalent to using the URL to describe the resource, something like http://www.test.com/products/191/ then using this as the basis of your rewrite.
In newer versions of IIS though (7 and above) you can use the URL Rewriting to build translation from one URL to another on the fly.
Links
URL Rewrite (download link)
Using the URL Rewrite Module

Unable to open a published MVC Project

I'm a total beginner so sorry in advance.
I used VS13 to build a MVC project and published it to my webspace. Now I'm unsure which file or path I need to specify in my forwarding config in order to open the website.
I tried
/Views/Shared
to get _Layout.cshtml and
/Views/Home
to get Index.cshtml but none of these are working. I also changed some admissions but it always shows me this
Forbidden - You don't have permission to access / on this server.
when I'm trying to open the website.
Any ideas on what I'm doing wrong?
With MVC You don't access views like traditional ASP.NET WebForms i.e. /path/to/view.aspx. Everything is handled via routing & controllers.
By default you will have a HomeController which will have an Index action which is invoked via a GET request. Assuming you haven't changed any of the default routing configuration you would just need to navigate to www.domainname.com/home to see your Index page.
The default routing configuration looks like /controller/action/parameters, MVC will always work this way unless you tell it different. If you don't pass a specific action (like I didn't with the home url) the Index action of the controller is assumed.

asp.net mvc routing, ignore route with extension in the middle of url

Hi How can make the asp.net routing engine ignore routes with an extension of the type
/pathtofile/filename.aspx/morepaths
I know this is hardly a real scenario but I need to know for another similar issue for an autogenerated url
Thanks
The MVC routing engine will not intercept a url if there is a matching file on the file system. (See RouteCollection.Ignore Method) So your example url will work fine. Query strings will also work fine.
You can test this out as follows:
Create an MVC application in Visual Studio
Run it
In your browser enter the url of the Site.css file in the Contents folder.
The file will be served and the browser will pop up the "Save" dialog.
Create an html file anywhere on the site and enter the url.
Your browser will display the html page.
Create an aspx web form anywhere on the site and enter the url.
Your browser will display the web form.
Add a query string or additional path to the url.
Your browser will display the web form.
You can also do this with .asp (classic ASP) pages (although the VS web server won't serve .asp pages, you have to set the site up in IIS for that to work.)
I hope that answers your question.

Wordpress with ASP.NET MVC

I have Wordpress in a subfolder in my site named blog.
When I goto the url of my site /blog/ I get the error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
This use to show the default theme and an empty blog.
I think it may be a routing problem with MVC?
Does anyone know how to correctly set this up or how the routes should be configured?
Try putting this in your RegisterRoutes handler in global.asax:
routes.IgnoreRoute("blog/{*subfolder}");
It might also work simply with blog/*, but I am not quite sure.

Trying to make Weborb .NET work with ASP.NET MVC

We have been using weborb for .net on an existing application for some time now and it has worked very well. We decided to rewrite our application in ASP.NET MVC and now I need to make weborb work with mvc. I have been getting a 404 the resource cannot be found error while trying to connect to the weborb.aspx page. I have added all of the appropriate entries to the web.config file and I even found this article explaining how to make the two work together
http://aspzone.com/tech/how-to-get-weborb-and-asp-net-mvc-to-work-together/
But to no avail. I can't make it work. Thanks.
If 404 is given then there is no such resource. Most likely the MVC tries to route the request and cannot find appropriate one.
Try to add ignore route in the beginning of routes registration. Something like this:
routes.IgnoreRoute("weborb.aspx/{*pathInfo}");
My problem was that I had the project set up incorrectly as a website and not an mvc application. Once I did that the route explained the blog post I referenced worked like a charm.

Resources