Best DotNetNuke url rewriting approach? - asp.net

I would like to implement a URL rewrriter for DotNetNuke. Have questions as to whether this is a good or possible approach and any suggestions other developers may have.
Can I add a dynamic or static route for URL rewriter from the 'Pages'-> 'Add Page' section?
Let's say I'm creating a page called 'Events' underneath the 'Activities' menu item.
Can I write some custom code in DotNetNuke that will add a prompt on the add page screen that assumes I will want a static or dynamic route added for - site.com/Activities/Events Or if I name the page 'Event Calendar' then it would suggest 'site.com/Activities/Event-Calendar'?
I would like any feedback or suggestions on how I would accomplish this! Thank you.

If you're using DotNetNuke 4.8 or greater, you just need to enable Human Friendly Urls through the Web.Config.
To enable human friendly urls, replace:
<add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includePageName="true" regexMatch="[^a-zA-Z0-9 _-]" />
with:
<add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includePageName="true" regexMatch="[^a-zA-Z0-9 _-]" urlFormat="HumanFriendly" />
UPDATE:
For DNN 7.x and greater, this should now be:
<add name="DNNFriendlyUrl" type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules" includePageName="true" regexMatch="[^a-zA-Z0-9 _-]" urlFormat="advanced" />
Additional Detail: Enable Human Friendly Urls in DotNetNuke

Check this out - details here:
http://www.ifinity.com.au/Blog/Technical_Blog/EntryId/19/Rewriting-the-DotNetNuke-Url-Rewriter-Module/
Also, take a look at the existing FriendlyUrl module that's already included in DNN.
If you want to do this on the stock pages, you'll need to crack open the source for it, or write a module that does this independently.

To answer your question directly : yes, you can add some code to the DNN Page Settings page. However, you'll be modifying the core code and thus won't be able to easily upgrade your installation when the next DNN release is made.
A lot of people come to DNN and want to write a new Url Rewriter. The problem is not the rewriting : it's getting the DNN framework to generate the correct urls where you would like them - in the menus, in generated links within modules. To really change the rewriting scheme you need to replace/augment the Url Rewriting function, the friendly url generation function, and provide some sort of redirect capability in order to tie old and new Urls together.

Another suggestion is Page Blaster, if you are not wishing write your own code. Works well for the sites l use it on.

Several of these are great replies... One of the most important things to know if you are just learning about DNN now (2016 and above) is that the realm of URL Rewriting has changed over time within DNN.
Before, in DNN 4.8 and below you had to use an external module/provider such as:
PageBlaster or
DNN Masters SEO URL REWriter or
iFinity URL REWriter
all of those are mentioned in some of the answers above.
However, after DNN 4.9, iFinity URL ReWriter was incorporated into the DNN core and you'll find it available in DNN 5, 6, 7,and 8 in different levels of exposure to the interface. You still need to do some updates in the web.config, but much of it is done directly within the Page Settings now.
Any settings that are not within the main managers, you can do either in the web.config, or in the database, or you can look for a DNN module such as X3 DNN URL Management which taps into the database records of the integrated DNN url rewriter and helps manage settings (it is very similar to the old iFinity interface screens/options) but you don't need it, you can work directly, it's just helpful.

Related

Asp.net 2.0 Hide Default.aspx from Url

I have one issue with my site. I need to hide Default.aspx from Url. My web site project uses urlrewriter net and I tried using it to make this but no success.
I read lot of articles on net how to do this but nothings work.
Does this is only possible to set on IIS ?
I wont all ways to have www.test.com instead of www.test.com/default.aspx
Please for best solution ?
If you're using iis 7 or above, this might be a way of going about it.
The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find. You can use the URL Rewrite module to perform URL manipulation tasks.
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
And heres a link to see the module in action.
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
After reading tons of articles this is solution for my problem..
setting this javascript onto masterpage
var testremove = location.href.toLowerCase().indexOf("default.aspx");
if (testremove != -1) {location.replace(location.href.substring(0,testremove))};

How to register a IHttpModule in Orchard which has access to the DefaultContentManager (or the equivalent)

I have been trying to write something for orchard which will check all requests for "_escaped_fragment_" signifying a google ajax crawling request and will perform a 301 redirect to the correct resource which needs to be looked up using the DefaultContentManager.
I had done something like this in a previous project by extending IHttpModule and registering it using
<httpModules>
<add name="GoogleRedirect" type="MyNameSpace.GoogleRedirect"/>
</httpModules>
but have found that using the same approach I can't get access to the orchard content manager.
ie. the following doesn't work
_contentManager = DependencyResolver.Current.GetService<IContentManager>();
I also noticed that Orchard uses Autofac and have been trying to get a line similar to ContainerBuilder().Build().Resolve<IContentManager>() working but the ContainerBuilder doesn't seem to be exposed anywhere?
Is there any way of accessing the DefaultContentManager without having to rewrite the code I currenty have? If not is there a special Orchard way of doing this? What is the easiest way to do it and are there any guides to doing anything similar / any bits of code I can examine? I have been reading through the documentation but not sure of the best way of doing it?
Will carry on reading anyway any help appreciated.
Update
After doing some searching I found the following post:
http://www.deepcode.co.uk/2011/05/real-world-orchard-cms-part-4-cleaning.html
Which has an example of using filters. Just in case anyone else has any problems, I found that my Themes folder was never hitting any of the break points. After comparing with another project I noticed that the theme I had created did not have its own project file. To sort this out I recreated my theme using
codegen theme MyTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true
No, I don't think this is possible. Any particular reason why you need to do this in a module rather than, say, a filter?

Rewrite URLs for DNN

I have a site and already trying to do a little url rewritting but want to know if there is a solution to make it better
my current state urls look like this
http://snit.us/Home/tabid/314/CN/1/RE/23/United_States_Missouri.aspx
I want to change them to something more ordered so in my new scheme i want to do this
http://snit.us/Home/United_States/Missouri/default.aspx
obviously the point is that if i remove missouri from the new url it would find all United_States - etc etc etc
even better would be to have http://snit.us/Home/United_States/Missouri so its even less cluttered
I think your best bet would be to implement the free iFinity URL Rewriter for DotNetNuke. At the very least, you should be able to achieve the following:
http://snit.us/Home/CN/1/RE/23/United_States_Missouri
If you're using IIS 6, you'll want to enable extensionless URLs in IIS. If you're using IIS 7, you should not need to make any changes.
To set it up, you'll just need to add the DLL that iFinity provides to your site's bin directory and then follow the instructions that came with the download for configuring your web.config (make sure to make a backup copy of your web.config for safety and convenience).
Here is an example configuration that we use on dnnGallery.net:
<add name="Ifinity.FriendlyUrl" type="iFinity.DNN.Modules.FriendlyUrl.DNNFriendlyUrlProvider, iFinity.FriendlyUrlProvider" includePageName="true" regexMatch="[^\+a-zA-Z0-9 _-]" urlFormat="HumanFriendly" redirectUnfriendly="true" doNotRewriteRegex="(\.axd)|(/DesktopModules/)" doNotRedirect="SearchResults;" doNotRedirectRegex="[.]*(/logoff.aspx)" pageExtensionUsage="never" parameterHandling="ordered" checkForDupUrls="true" forceLowerCase="true" redirectWrongCase="false" replaceSpaceWith="_" redirectDefaultPath="true" />

Change a website's directory names per installation

Is there a way that I can have different directory names per installation of a website? As in I would need to rename the directories at build time or some similar solution. I am currently using MSBuild with CruiseControl.NET.
An example would be I have a module in my website called Bug Tracking which is then in http://mysite.com/BugTracking/.
One installation wants to leave it as BugTracking and another would like to call it "Issue Tracking" for whatever reason and have it in http://theirsite.com/IssueTracking/.
Re-writer rules
You could set up a re-writer rules so you could leave the directory name the same, and just add a re-writer rule for the clients that want it call something different?
IIS7
also look at Scott's blog
Doesn't solve the problem, kind of hides it I know. but its easy :)
or
ASP.NET Routing:
Also worth looking at would be ASP.NET Routing,
Using ASP.NET Routing Without ASP.NET MVC
or
Using Routing With WebForms

How to SEO friendly an existing ASP .NET 3.5 web application under IIS6

So, I know there's a lot of this subject here and over the Internet. But most articles/questions refers to "static" url rewriting, like:
www.site.com/products.aspx?category=Books
So they rewrite it to
www.site.com/Products/Books
That's ok but I need something else.
The site is like a CMS, it has different types of content.
Nowadays to read the article titled "How StackOverflow helps you in your development" you need to go to an URL like the following.
www.site.com/viewContent.aspx?Id=1234
What I want to achive is:
www.site.com/Content/Articles/how-to-stackoverflow-helps-you-in-your-development
So as I understand, I need to involve ASP .NET in that, because first I need to retrieve the article (an its title of course) and then rewrite the URL.
But I'm wondering how the hell ASP .NET will know how to get that article if I go to that URL, it doesn't include the id anywhere...
So maybe I could accept something like
www.site.com/Content/Articles/1234/how-to-stackoverflow-helps-you-in-your-development
I'm kind of lost here really.. I've never done any URL Rewriting at all and I've googled a lot and I cannot find a way to do what I want. Maybe what I want is not called url rewriting??? I don't know...
The site is running under Windows 2003 Server, IIS6, ASP .NET 3.5 SP1
And of course, I need a free solution, cannot spend 100usd on the ISAPI mod (besides I don't know if that is going to do what I need).
Thanks to all and sorry if this is a duplicated question, but I couldn't find it.
EDIT: I don't need to support non-ASP.NET files (jpgs, gifs, etc) don't need to be rewritten. I just need to rewrite the viewContent page to include the content title into the URL.
You can use the new Routing that comes with ASP.Net 3.5 sp1 to have clean URLs.
This can even be done in web forms and not just MVC. ( I have done it myself). See here and here for exanples of how to set it up.
You can throw the Id of the article and the title in the URL and make the Id the real parameter that gets used to search for the article. That is what SO does. Try removing the question for the URL and it will take you to the same place.
Even if you don't use the Id you can pass the title of the article "how-to-stackoverflow-helps-you-in-your-development" to your DB and retreive the article based on the title.
With regards to IIS 6 it is a little trickier since IIS 6 by default can't handle extension-less URL's.
There are a few work arounds:
Use the wildcard mapping in IIS to map all requests to Asp.Net
Put Default.aspx at the end of your urls
See this post for other possible solutions.
Although the first solution may have performance issues if all content in your site goes through Asp.Net (even images, css, .html ...) in a small site it shouldn't matter. I have used this approach and there wasn't any major performance issues. I think it is the simplest solution. Here is the website I built with it
I hope this helps.
This one is free, I have used it and it works pretty well: http://www.codeplex.com/IIRF
The nice thing is that it will handle url's without an extension (i.e. .aspx, .html, etc.)
You can achieve this with ASP.NET routing.You can do this with ASP.NET MVC as well as Webforms.No need to do anything with IIS.
Check the below link
https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink
I did URL routing in my web application within 1 hour with the details from the above link.Its quite simple to learn .They provide sample codes too.It will help you to do it easily
You can retrieve the Id of the content using the title.But title should be unique.You can use ajax to check whether the title is a already existing one when user takes mouse out from the textbox.
Easiest way is to add a http module to your current webforms project.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This shows you the basics of it, But it can easily be expanded so that the pages you want to rewite is taken from a database or even built on the fly.
ASP.net MVC is your friend for that
stackoverflow use MVC

Resources