Url Rewriting in Umbraco 5 Jupiter - asp.net-mvc

i want to do simple URL re-writing in Umbraco 5 like we used to do in previous versions i-e changing the UrlRewriting.config file, or we used to do it in Asp .Net
<rewriter>
<rewrite url="~/en/faq.aspx" to="~/faq.aspx" />
</rewrite>
I know we can create new area in the application and then add new routes in areaRegisteration.cs. but then the problem of mapping these controllers to the default Views arises, as the views are in: Views > Umbraco Directory of the application.
For example,
I create a new Area Named "En" and add Route in EngAreaRegisteration.cs, i-e
context.MapRoute("en_property","en/{city}/{controller}/{action}",new { } );
then how i can map the Actions to any Umbraco Page, i dont think the Redirect is a solution as redirect will change the Url,
my URL will be like this, en/paris/property/book
i am using Umbraco 5.0.1 Web deploy.
Thanks in Advance
Sher

Related

Issue with prerender.io always rendering the default angular route for a list of client side routes

Just want to say I really like prerender.io, but I am currently having an issue with it and I am wondering if maybe I am doing something wrong and people with more experience with the service can help me out.
I am having the same issue with the prerender.io site and also with a Debian Linux box I setup with prerender for local execution.
My new site is a hybrid of ASP.Net MVC and angular, where angular represents workflows (or categories of content) within MVC routes on the server.
An example of a category of content is this:
http://[somesitename]/PublicContent/#!/news
http://[somesitename]/PublicContent/#!/welcome
The MVC server side route is:
http://[somesitename]/PublicContent
and #!/news and #!/welcome are the angular app routes and welcome is also the default route.
When I send my URL to the prerender.io service or my local instance:
http://service.prerender.io/http://[somesitename]/PublicContent/#!/news
The prerender service is only ever rendering:
http://[somesitename]/PublicContent
and is ignoring the client side route after the #!
so for all my pages for each MVC route I am merely getting the default route rendered multiple times...
Is this a bug with prerender.io? Or do I not have something not properly configurered?
I do have the:
<meta name="fragment" content="!">
in the head for all my pages if that would matter.
Talked with the guys over at prerender.io, and it appears that a modification I made to the Asp.Net MVC middleware where it was removing ?_escpaed_fragment_=/ completely was an incorrect modification to this code, which itself was incorrect (the base code removed ?_escpaed_fragment_=/ and replaced it with nothing, I modified the code to remove ?_escpaed_fragment_=/ and replace it with #!).
The prerender.io service expected ?_escpaed_fragment_=/ to exist in the URL and if it finds it it will replace it with #! before calling your website to cache the page. It doesn't expect to find the #!, so it won't properly process the URL if it is there.
So if you are using the Asp.Net MVC middleware you should comment out the following code from PrerenderModule.cs:
// Remove the _escaped_fragment_ from the URL if it exists!
var escapedFull = "?" + _Escaped_Fragment + "=/";
if (url.Contains(escapedFull))
{
url = url.Replace(escapedFull, string.Empty);
}

Another ASP to MVC migration > routes

Migrating our classic ASP site to ASP.Net 4.5 MVC. Our site is pretty large, hundreds of file, and SEO optimized. All URLs are SEO friendly, via web.config, eg.:
www.ourdomain.com/articles/2013/120/the-best-article
www.ourdomain.com/blog/2013/122/the-best-blog
www.ourdomain.com/video/2013/123/the-best-video
ie. www.ourdomain.com/{contenttype}/{year}/{id}/{url encoded title}
The ASP files to render are stored in a folder like /render/content.asp
We don't want to change any URLs in this migration. The new files of the MVC app will be in all new directories than the existing site. For example, a view: /MVC/content.vbhtml
How would you go about adding links in your Views, with ActionLink or other, to use the existing SEO friendly path instead of the default path, without hardcoding the path in the links in the view (adopt from currently URL, more or less). For example:
#Html.ActionLink("Edit", "Edit", New With {.id = currentItem.ID})
That creates an Edit link like : /MVC/Edit/120
But, what I would like is: /article/edit/120.
Any help appreciated.
Use
#Html.RouteLink("Edit", "myRouteName", New With { ... route params ... } );

MVC3 Web Application Will Not Publish

I am trying to learn MVC 3, so I am a noob. For now, I just want to make a basic site, that is an HTML page using jQuery and CSS. While I am using MVC, I don't really need a model, since there is not really any data being passed to the application. However, this is creating a problem for me, because I am getting a HTTP 403.14 Forbidden error when I try to publish this site. I think that there is something wrong with the way the application is structured that will not allow it to execute properly when I got to localhost:1081 web site. Here is all I have:
HomeController.cs
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
This just returns the view of Index.cshtml.
Index.cshtml:
#{ViewBag.Title = "My Web Site";} <h2>Web Site Title</h2>
All of my HTML code was put into _Layout.cshtml. jQuery and CSS are used. The site works fine when I do the debug option, but when I try to publish it gives me 403.14 forbidden. I have run the inline command aspnet_regiis -i and it seemed to work, but did not allow the project to run.
Global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
If I move the code in _Layout to Index, it doesn't work. Is there a way I should be linking this to Index.cshtml?
Web.config:
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="_Layout.cshtml" />
</files>
</defaultDocument>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
I do not want directory browsing, and I have tried to play with this option as well. If I enable, it allows me to see the contents but does not render the page.
So two questions: 1.) Do I need to have a model, even though I am not passing any data to the application, just trying to render a site? 2.) Is my site set up / structured properly or what exactly am I doing wrong here?
Thanks,
Nick
No, you don't need a model.
First, don't use the default document. MVC overrides the default document handling and uses the route system.
Second, you don't want to try and use the Layout page as your document. Layout is like a master page, and is used to create a wrapper around your real document.
Third, saying "will not publish" means that you are having problems actually publishing the site via the publish mechanism. Your problem is not that you can't publish, because obviously it is doing so, but that your site isn't executing.
Fourth, 403.14 means it's trying to list the contents of directory, but this shouldn't happen if MVC is configured correctly because MVC's routing takes over. This means you have a problem somewhere in the asp.net pipeline.
Where are you publishing to? Did you configure IIS to setup a site at this location? Given that you are trying to access the site from a different port number, It would seem to me that you have not setup IIS to do this and are instead trying to use the same port that's used for debugging.
In order to publish a site, IIS must be configured to use that location.

Umbraco Alternative Links doesn't work

Hello I created some page in Umbraco 4.7 CMS,
configure some alternative links to page(section) it looks like.
If I look at
Link to document
/folder/folder2/page1.aspx - workig
Alternative Links
http://site.com/folder/folder2/page1.aspx - workig
http://site.com/en/folder/folder2/page1.aspx - not working
http://site.com/old-folder/folder2/page1.aspx - not working
but in browser just /folder/folder2/page1.aspx show a valid page other links redirect users to 404 page that configured in umbraco config file.
Have you considered using the UrlRewriting module to get this working. You could add a new rule similar to the following:
<add name="page1rewrite"
virtualUrl="^~/en/folder/folder2/page1.aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/folder/folder2/page2.aspx"
ignoreCase="true" />
This could be further improved depending on your exact requirements but you could it you wanted rewrite all urls ~/en/folder/folder2/ to the new location.
An alternative option would be to use the umbracoUrlAlias document type property.

Generating Outbound Links To Main Website From Widget

I've got an ASP.NET MVC 3 web application that lives on server 1:
http://www.mysite.com
And i've got a widget (also ASP.NET MVC 3 web application) that lives on server 2:
http://widget.www.mysite.com
Now, i want to generate a link to the main website from my widget.
So if i do something like this in the widget project:
#Html.RouteLink("Outbound link", "MainWebsiteRoute", "http", "http://www.mysite.com", string.Empty, null)
It will error (or generate the wrong link) because the route tables are different between the widget and website project.
Even if i copy the route from the main website into the widget one, the controllers/actions don't exist in the widget project, so it won't work.
How do i do it? Do i have to hardcode the URL's?
Ended up duping the routes from the main website that i need in the widget.
Example route in main website:
context.MapRoute(
"Q&A - Individual Q",
"{locationUniqueUri}/questions/{questionUniqueUri}",
new { controller = "Questions", action = "Detail" },
);
Duped route in widget:
RouteTable.Routes.MapRoute(
"Outbound - Q&A - Individual Q",
"{locationUniqueUri}/questions/{questionUniqueUri}"
);
Notice how there are no route defaults - that's because i don't care, since that's concerning matching the route to a controller/action. But this happens in the website, not the widget. All i'm concerned about is generating the URL.
I then created a simple wrapper for RouteLink called OutboundRouteLink which specifies the hostname (for the main website), and generates the link.
I don't think it's too bad a solution. Obviously, it's hard-coded in a way - if the routes change in the main website then i'll have to change the widget routes. But that fine, because if one of my URL's changed, i'd have to do 301's anyway, so the old URL's would still work for the widget (they would get 301'd).
Also, i could go one step further and store the route url in a config file and share that between the projects, which would give me a bit more safety. But there's only around 3 outbound URL's so this should be fine.
Not saying this is the best way to handle it, but im happy with it.
Are you using areas? If not, then perhaps you should be. That way you could simply supply the area for the route and it would be able to resolve the url for you. Given your sample URLs you could build your main site with your widget site as an area. Supplying a empty string for the area parameter in the route values would allow you to reference a controller/action in the main site from the widget site.

Resources