I'm attempting to connect to my published website using the following url.
http://www.mywebsite.com/
I keep getting:
The incoming request does not match any route.
Here are my routing rules:
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Default2", // Route name
"/", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
I'm using authentication as such:
<authentication mode="Forms" >
<forms loginUrl="~/Home.aspx/Index"
protection="All"
timeout="300"/>
</authentication>
When I'm not authenticated it goes to the correct page, but when I am authenticated it throws the above error. I'm using IIS 6.0 and doing the whole rewriting url workaround option.
What am I missing?
Change "/" in "Default2" route to "":
routes.MapRoute("Default2", "", new { ... });
Also make sure you have followed this guide: http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx for Default.aspx file if you are on IIS6.
Related
I have 2 asp.net mvc 4 applications:
MVCForum.site - opensource app with forum and
My.Site - site of my customer
Each of the applications has HomeController.
I need to deploy them to local IIS 7.5 like this:
my.Site -> localhost:81
I can get to it by URL localhost:81/home or localhost:81/
MVCForumSite.Site -> localhost:81/forum
I can get to it by URL localhost:81/forum
They work separettly, but routing conflict accuries when they start to work at the same time.
*If I use default configuration from customer with Azure emulater, so they work together, but I don't want to use the emulator, because each restart is too long for development.
MVCForum has next routes (bad if need to fix them):
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{favicon}", new { favicon = #"(./)?favicon.ico(/.*)?" });
routes.MapRouteLowercase(
"categoryUrls", // Route name
string.Concat(AppConstants.CategoryUrlIdentifier, "/{slug}"), // URL with parameters
new { controller = "Category", action = "Show", slug = UrlParameter.Optional } // Parameter defaults
);
routes.MapRouteLowercase(
"categoryRssUrls", // Route name
string.Concat(AppConstants.CategoryUrlIdentifier, "/rss/{slug}"), // URL with parameters
new { controller = "Category", action = "CategoryRss", slug = UrlParameter.Optional } // Parameter defaults
);
routes.MapRouteLowercase(
"topicUrls", // Route name
string.Concat(AppConstants.TopicUrlIdentifier, "/{slug}"), // URL with parameters
new { controller = "Topic", action = "Show", slug = UrlParameter.Optional } // Parameter defaults
);
routes.MapRouteLowercase(
"memberUrls", // Route name
string.Concat(AppConstants.MemberUrlIdentifier, "/{slug}"), // URL with parameters
new { controller = "Members", action = "GetByName", slug = UrlParameter.Optional } // Parameter defaults
);
routes.MapRouteLowercase(
"tagUrls", // Route name
string.Concat(AppConstants.TagsUrlIdentifier, "/{tag}"), // URL with parameters
new { controller = "Topic", action = "TopicsByTag", tag = UrlParameter.Optional } // Parameter defaults
);
routes.MapRouteLowercase(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
and My.Site 's RouteConfig.cs
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Could you please help me to deploy it.
Have you tried adding in an IgnoreRoute to your My.Site's RouteConfig.cs?
routes.IgnoreRoute("Forum/{*pathInfo}");
So the next thing has helped:
created a site in IIS called site.localhost.
Created an application inside that site.localhost->forum (like internal application)
Created a second fake site (for correct moving files while deployement) called fakeforum.localhost
site.localhost looks to C:\inetpub\MyWebsite\site
forum (site.localhost->forum) looks to C:\inetpub\MyWebsite\forum
5 fake forum fakeforum.localhost looks also to C:\inetpub\MyWebsite\forum this helps not to overwrite configs of site.localhost during the publishing of forum.
stop fakeforum.localhost in IIS and never run it
publish mvc app to site.localhost in Visual Studio using start url: localhost:81 and server name localhost, site name site.localhost (from IIS)
publish mvc forum app to fakeforum.localhost using start url: localhost:81/forum
server name localhost, site name fakeforum.localhost (from IIS)
What it does?
It helps to publish - to move files from dev folder to intepub and let xdt:Transform work and don't change you original web.config inside folder for development.
It uses IIS in is a cantainer for publishing without running.
I recently switched my mvc3 localization structure from lang as subdomain (fr.domain.com) to lang as path (domain.com/fr).
Everything works fine but the automatic redirection to account logon.
Let's say I'm not authenticated and I try to access domain.com/fr/test I'm redirected to domain.com/Account/LogOn?ReturnUrl...
How can I configure my site so that I get redirected to /fr/Account/LogOn?ReturnUrl...
edit :
I use route mapping
routes.MapRoute(
"DefaultLocalized", // Route name
"{lang}/{controller}/{action}/{id}", // URL with parameters
new { lang = "en", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
, new { lang = "fr" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
SOLUTION :
Here is my solution implementation based on developer10214's suggestion
public ActionResult LogOn()
{
if (System.Web.HttpContext.Current.Request.Url.Query.Contains("%2ffr%2f") && System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName != "fr")
return Redirect("/fr/Account/LogOn" + System.Web.HttpContext.Current.Request.Url.Query);
LogOnModel model = new LogOnModel() { UserName = "", Password = "" };
return View(model);
}
I think the reason why you get redirected to the common account/logon action is, that this path is configured in your memebership section in your web.config. Every request for an action which is protected by the Authorize attribute will end up there, if you are not logged in.
A possible solution could be:
change the logon action, by extracting lang parameter from the return url and redirect to the correct logon action
The default route in ASP.net MVC is the following:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
This means that I can reach the HomeController / Index action method in multiple ways:
http://localhost/home/index
http://localhost/home/
http://localhost/
How can I avoid having three URL's for the same action?
If you want only:
http://localhost/
then:
routes.MapRoute(
"Default",
"",
new { controller = "Home", action = "Index" }
);
If you want only:
http://localhost/home/
then:
routes.MapRoute(
"Default",
"home",
new { controller = "Home", action = "Index" }
);
and if you want only:
http://localhost/home/index
then:
routes.MapRoute(
"Default",
"home/index",
new { controller = "Home", action = "Index" }
);
You are seeing the default values kick in.
Get rid of the default values for controller and action.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {id = UrlParameter.Optional } // Parameter defaults
);
This will make a user type in the controller & action.
I don't suppose you are doing this for SEO? Google penalises you for duplicate content so it is worthy of some thought.
If this is the case routing is not the best way to approach your problem. You should add a canonical link in the <head> of your homepage. So put <link href="http://www.mysite.com" ref="canonical" /> in the head of your Views/Home/Index.aspx page and whatever url search engines access your homepage from, all SEO value will be attributed to the url referenced in the canonical link.
More info: about the canonical tag
I wrote an article last year about SEO concerns from a developer perspective too if you are looking at this kind of stuff
I'm trying to add a route that will transfer all sitemap.xml requests to a custom request handler I made.
I tried using the following code:
routes.Add(new Route("sitemap.xml", new Helpers.SiteMapRouteHandler()));
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
But when I make a link using Url.Action():
Url.Action("Index", new { controller = "About"})
I get the following when I try to navigate to the XML file:
/sitemap.xml?action=Index&controller=About
What am I doing wrong?
ANSWER:
I used this solution:
Specifying exact path for my ASP.NET Http Handler
If you want to route to and action instead to a request handler
You could add a route like this
routes.MapRoute(
"Sitemap",
"sitemap.xml",
new { controller = "Home", action = "SiteMap" }
);
as mentioned here - MVC: How to route /sitemap.xml to an ActionResult? and it worked for me
Update: Also ensure that <modules runAllManagedModulesForAllRequests="true"> is set.
I'm not sure if this will solve the problem, but it's worth a try:
routes.Add(
new Route(
"{request}",
new RouteValueDictionary(new { id = "" }), // this might be the tricky part to change
new RouteValueDictionary(new { request = "sitemap.xml" }),
new Helpers.SiteMapRouteHandler()
));
You have to add a handler to web.config file.
<add name="SitemapFileHandler" path="sitemap.xml" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
And configure your routes:
routes.RouteExistingFiles = true;
Read more here:
http://weblogs.asp.net/jongalloway//asp-net-mvc-routing-intercepting-file-requests-like-index-html-and-what-it-teaches-about-how-routing-works
I have a route:
routes.MapRoute(
"Company",
"{id}/{name}.aspx",
new { controller = "Company", action = "CompanyIndex" }
);
I need redirect to the same URL, but without ".aspx" extension:
routes.MapRoute(
"Company",
"{id}/{name}",
new { controller = "Company", action = "CompanyIndex" }
);
But the old URL (with aspx extension) can't return 404 error code. It just need redirect using 301 permanent redirect.
Create a redirection handler. Link