What's the best way to implement friendly URL in ASP.net?
The ASP.NET Routing Framework provided in .NET 3.5 SP1 is a good one.
Although it is very new, it can handles many URL-related tasks and most frequently used URL-friendly schemes very well.
It can be used outside of MVC, too.
The best way to do this is to look into the new MVC toolkit from microsoft (http://www.asp.net/mvc/)
See http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx for an example.
Sure, its only beta right now, but the core of it is the routing system that makes it possible to make intelligent urls based on actual content.
I.e. to edit product with id 5 you'd have an url that looked like
/Product/Edit/5
If I read the specifications correctly, you can use this routing system for anything (i.e. so you don't have to recode the entire site to use it), and it can default to allow direct references to an existing file to have precedence over its own rules (i.e. /myfile.aspx will still use the file, instead of a route). That way you can mix and match the technologies and urls while you make the trancendance to the new routing based system.
I have used UrlRewriter.Net library. It is small but powerful and easy to configure.
If you're looking to do this in earlier versions of the .Net Framework, you can use the RemapURL tool from the IIS 6.0 Resource Kit. We use it, and all it takes is installing the dll, creating a very simple ini file with your friendly urls and their associated endpoints, and enabling the dll in Web Service Extensions Very simple how-to here.
Related
I am building a website with asp.net. But I have an issue: I want to make user profile page link like in facebook.
For example,
"hostname.com/username" instead of "hostname.com/profile.aspx?something=something"
How can I achieve this?
Thank you for your time and valuable answers.
That feature called "URL Routing". If you are using MVC, then MVC Framework has That feature included. But if you are using Web Forms application, then You have to do this manual.
For Web Forms application, You can use Nuget Package Microsoft.AspNet.FriendlyUrls to make your application so that it generate url's what you want.
Refer http://www.devcurry.com/2013/05/friendly-urls-in-aspnet-web-forms.html
http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx (This is microsoft suggested)
This is typically done with a framework of some kind, but the concept it fairly simple --
If you're trying to do this quickly, you'll want to do your research on which one to use, but I'll explain the principle that makes it work -
In your server config (like an .htaccess) - you will rewrite the requests for *.aspx files go to a central index.aspx - this file then bootstraps your index however you want -
In your case, it would take the /username portion and query the database for a user with that username, fetch the associated data, and do whatever with it.
It's a relatively simple concept, and you could write something of your own device to bootstrap the request to your code, but you're probably better off looking for some (micro)framework that handles all that for you...
Good luck - !
I am about to write a tender. The solution might be a PHP based CMS. Later I might want to integrate an ASP.NET framework and make it look like one site.
What features would make this relatively easy.
Would OpenId and similar make a difference?
In the PHP world Joomla is supposed to be more integrative than Druapal. What are the important differences here?
Are there spesific frameworks in ASP.NET, Python or Ruby that are more open to integration than others?
The most important thing is going to be putting as much of the look-and-feel in a format that can be shared by any platforms. That means you should develop a standard set of CSS files and (X)HTML files which can be imported (or directly presented) in any of those platform options. Think about it as writing a dynamic library that can be loaded by different programs.
Using OpenID for authentication, if all of your platform options support it, would be nice, but remember that each platform is going to require additional user metadata be stored for each user (preferences, last login, permissions/roles, etc) which you'll still have to wrangle between them. OpenID only solves the authentication problem, not the authorization or preferences problems.
Lastly, since there are so many options, I would stick to cross-platform solutions. That will leave you the most options going forward. There's no compelling advantage IMHO to using ASP.NET if there's a chance you may one day integrate with other systems or move to another system.
I think that most important thing is to choose the right server. The server needs to have adequate modules. Apache would be good choice as it supports all that you want, including mod_aspnet (which I didn't test, but many people say it works).
If you think asp.net integration is certanly going to come, I would choose Windows as OS as it will certanly be easier.
You could also install reverse proxy that would decide which server to render content based on request - if user request aspx page, proxy will connect to the IIS and windoze page, if it asks for php it can connect to other server. The problem with this approach is shared memory & state, which could be solved with carefull design to support this - like shared database holding all state information and model data....
OpenID doesn't make a difference - there are libs for any framework you choose.
I am making a making a new asp.net web forms site and would like to beautify my urls - I want to accept a url like this one "www.mysite.com/1-2,3" and turn it one like this "www.mysite.com/page.aspx?a=1&b=2&c=3". Which option is best for this task - IIS7 Url Rewriting or Routing in terms of performance and ease of maintenance. Btw I am planning to use medium trust shared hosting IIS7, maybe 6.
In the past I used PHP's mod_rewrite, which I was quite happy with, however now this whole site is being translated to ASP.NET, and I don't know which option to pick.
PS - I have already read this and this, however didn't find it clear enough for my problem.
I would make a strong argument for using routing. It keeps the request-resource resolution logic within your application, so it's very easy to add application-dependent logic when you need, and it eliminates the need to maintain synchronization between your application and a separate configuration resource.
Routing works great with traditional webforms.
URL rewriting is often (though not always) a compensation for a problem, rather than a solution - server software and frameworks still built around the older notion of web pages, which represent physical resources. However, web applications should react to requests as commands; but only relatively recent, modern web frameworks have begun to support that model natively. Routing is one of those developments.
I would strongly suggest to use routing,
it will in fact be more integrated with webforms in next version of the framework.
URL rewriting is more of a "hack" due to the lack of the routing in the first place. If you already have a project that you want to "shine up", then url rewriting will do just fine.
But when starting from scratch, I would definitely use routing.
Routing hides you application structure and makes you think more of your urls, as path to the content that you want to show, opposed to the path to some page with params.
And you don't have to keep track of 2 things when changing stuff, like you would with rewriting.
more in this article
IIS 5/6 used ISAPI filtering which was basically the equivalent of mod_rewrite for IIS. I hear that IIS7's url rewriting is a lot easier to manage and configure than ISAPI.
Well it depends on whether you're using classic ASP.Net or the new MVC framework. I don't have any experience with the MVC framework, but it sounds like it supports what you're looking for right out of the box.
On the classic ASP.Net side of things, we're currently using an IIS extension called ISAPI_Rewrite. It behaves similarly to Apache's mod_Rewrite and they have a free version you can use that has most of the power of the paid version ($100).
We are developing a CMS in ASP.NET. We love the idea of add-ons (like in Wordpress, where any developer can add a menu button or a widget) and would like to enable developers to do the same with our system.
However I think that the fact that C# is a compiled language is an obstacle in the way of add-ons.
Am I right? Or is there a way to create add-ons for a ASP.NET application?
The fact that C# is a compiled language isn't a problem at all. In fact the .NET framework should make it relatively easy to load other code (just as Java does, for the same reason). Look into the Managed Extensibility Framework, which is all about loading Add-Ons in managed code.
It's not an obstacle at all. MEF has already been mentioned, you could also use:
System.Addin
Mono.Addins
I'm not sure for ASP.NET specifically, but in the only compiled programming language I know (Objective-C/Cocoa), there's the concept of Bundles that can be loaded dynamically. I'm not sure how that works on the backend, but I'd guess that there is some similar system for C#/ASP.NET.
I don't know how it's done in Wordpress, but there should be many ways. You can allow developers to upload their assemblies with compiled code or you can allow them to upload code in C# or IronPython or anything that supported and compile it dynamically. Maybe you can use WebParts for your task.
Microsoft has created the Managed Extensibility Framework (MEF), specifically for this problem: providing .NET plugins for .NET applications. It is the framework that (future versions of) Visual Studio use for writing managed plugins.
However, please consider using a dynamic scripting language for this! Problems like this are exactly what they are specifically designed for. If you host the Dynamic Language Runtime in your application, it not only means that your users can extend the application in a scripting language, but even in any dynamic language (scripting or otherwise) for which a DLR implementation exists: Ruby, Python, Smalltalk, Scheme, JavaScript, PHP, you name it. Biggest disadvantage: the DLR hasn't been released yet.
In C#, you can create any assemblies, link them as DLL files and then do whatever you want.
The usual case would be to define some kind of Plugin Interface which must be implemented by all the plugins.
Then you can load all plugins from the filesystem (by iterating over the plugin DLLs), find the class inside which implements the interface, instantiate it and work with it.
If you want to provide plugins with unloadability and security, you could create an application domain and load the plugins to that, increasing complexity, but also increasing stability (a bad plugin won't crash your app).
Please ask more specifically if you want a specific answer :-)
It's not too difficult to put hooks in place. You have to define in advance where the add-on features will appear. For example: when drawing a menu you can use reflection to search other dlls (with specific names and locations) for a "BuildMenu" function. You'll be defining the API for this function signature. It may have to return a list of items to be added to the base menu items collection.
I'm currently using Intelligencia.UrlRewriter does anyone have better suggestions?
System.Web.Routing is part of .NET 3.5 SP1 and you can use it both for your ASP.NET WebForm-application and your MVC-application.
The official ASP.NET site has a good QuickStart Tutorial on System.Web.Routing.
ISAPI_Rewrite is also a good generic solution - works not only with ASP.NET but with any other system.
An alternative approach to consider is URL routing. This is not the same as rewriting (rewriting involves changing one URL to another whilst routing involves directly mapping dynamic URLs to different parts of your application) and is not so easy to implement for an existing project, but if you're starting a project from scratch you might find this a better approach depending on your exact requirements. On the other hand, it may be no use to you at all, but at least you can make an informed decision!
Following the suggestion made by Seb Nilsson I looked a bit all over google and found these nice examples:
aspnet routing goodbye url
rewriting
using asp.net routing independent
of mvc
using asp.net routing independent
of mvc passing-parameters
When working with IIS 6 it is important to have a look at this Blog
IIS 7 comes with a rewrite module
You can find further links in this wikipedia article