index.html is added to our route instead of id - asp.net-mvc

Recently, we've understood that Googlebot has faced 593 server errors in our website. After looking at the links, we understood that instead of id in our route, "index.html" is added.
These is the routes of our site:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "NewsView",
url: "news/{year}/{mounth}/{title}/{id}",
defaults: new { controller = "Home", action = "NewsView" }
);
We have generated the links as below:
#item.Title
This is our website's URL, of course as a sample:
http://www.ourwebsite.com/news/2016/01/this-is-the-title/14747
And this is the URL that Googlebot has faced:
http://www.ourwebsite.com/news/2016/01/this-is-the-title/index.html
In addition, in the "Linked from" tab of Google webmaster, there is the correct URL, which means that the corrupted URL has been linked from the same page with correct URL.
Also, we are using Microsoft URL Rewrite extension, which we have checked and has no rule for this.
Any Help would be highly appreciated

Related

Displaying Login Index When Project Url Types

This may be a simplest question, but I am faced with the following issue.
I have a project, and have the login view at http://localhost/Some.Web/Login/Index. If I type http://localhost/Some.Web/ I want to redirect it to login page. At the moment I am getting the "The resource cannot be found." error message. My route config has the following entry.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional }
);
What am I doing wrong. Open to suggestions.
there are two ways you can set custom routes like [routre("your route")]
when you set this the add this in your route.
routes.MapMvcAttributeRoutes(); to the routeconfig.cs file
and there is another way in your controller check if the user is authorize the redirect to that page other wise redirect to login page
if(userIsValid)
{
redirect("main page here")
}
else{
redirect("login page here")
}

Messing with start page in Visual Studios now opens to 403.14 error

What did I do http://localhost:11111/ doesn't work but http://localhost:11111/Home does? I've already tried Tools> Options > Open to start page and default start page
I think there's something wrong with routing. Check RouteConfig - there must be default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
pay attention on controller in defaults.

Asp.Net MVC localizing routes with default language

I need to provide language specific routes for my Asp.Net MVC application. The language should be part of the Url Path (http://myapp/en/Blog) and when it is ommitted the default language have to be used.
http://myapp/en/Blog -> Blog in the English version
http://myapp/Blog -> Blog in the Default (portuguese) Language version
To address this issue I created two Routes bellow:
routes.MapRoute(
name: "Default.lang",
url: "{lang}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { lang = #"^[a-zA-Z]{2}$" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The routes are working as expected but I'm getting weird results when I try to use the Url.RouteUrl method to get alternative language urls.
Example 1 - Path: /
url.Action("Index", "Blog") // returns "/Blog" that is OK
url.Action("Index", "Blog", new { lang = "en" }); // returns "/en/Blog" that is also OK
Example 2 - Path: /en
url.Action("Index", "Home") // returns "/en/Blog" (??????????) Not OK
url.Action("Index", "Home", new { lang = "en" }); // returns "/en/Blog" that is OK
As you can see I get a wrong result when I access the url http://myappurl/en and try to use the Url.Action method without pass any route value (same result with Url.RouteUrl)
Does anyone knows what is wrong with my routes?
[EDIT] I'm not sure if the issue is related to the route because I've tested the routes using "en" as first route's constraint and I got the same result.
After some digging inside System.Web.Mvc and System.Web.Routing source code I found that this behavior is expected. I presume that it is designed to correctly work in applications running inside Virtual Directories.
This can be confirmed in this answer that I found when was researching if someone else had the same problem with virtual path and route resolution.
Workaround
Use named route resolution with Url.RouteUrl method that has and different implementation and works as expected.
Example:
var blogDefaultUrl = url.RouteUrl("Default", new {action = "Index", controller = "Blog"});
var blogLangageSpecifictUrl = url.RouteUrl("Default.lang", new { action = "Index", controller = "Blog", lang = language });
I was avoiding to use named routes because my application design is a little bit more complicated than I demonstrated above. By this reason I have to discover at run time the route that matches the Request.Url and from that point I call the RouteUrl to get the alternative languages url to the content.

Dynamic Mvc route

I know there is a lot topics with the same name, but none of those I've found so far, have provided the answer I need.
I'm creating a "dropbox" site for my students to upload their projects on when they have to submit them to me.
The thing is that the students are able to create folders and I would like(if possible) to display the url based on the "folders" they are able to create on the website.
Folders could look like.
Home
Project
Project 1
Project 1 v1
Project 1 v2
And so on.
project 2
Submit
Basic the path could be short or long depends on the folder level.
Like : Home or Project/Project-1-v1/ or Project/Project-1-v1/Upload/Final
Is there a way to create a dynamic url/action that accept any of the above Path's ?
This can be done fairly easy.
My RouteConfig.cs
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute("CatchALL", "{controller}/{action}/{id}/{*catchall}",
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
My Controller
[Route("Home/{*catchall}")]
public ActionResult Part(string catchall)
{
return View();
}
If this was the url: http://stackoverflow.com/Home/36542665/dynamic-mvc-route catchall would contain = 36542665/dynamic-mvc-route

MVC Routing Removes Parameters

My current routing configuration looks as follows:
routes.MapRoute(
namespaces: new string[] { "ChiDesk.WebUI.Controllers" },
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The problem I'm running into is that if I link to the below address:http://localhost:20220/Public/Book?id=c231e3aa-a317-4321-88ef-fe989356babc
The routing appears to remove the id parameter part. So the address in the browser is set to:
http://localhost:20220/Public/Book
This obviously causes a problem if you refresh the page as the id parameter is not included anywhere.
What do I need to change on my routing to sort this out?
Thanks,
Gary
My mistake.
On my document ready function I was setting the history using replaceState. However I was using window.location.pathname property which does not include parameters.
Changing it to window.location has sorted this out.

Resources