Extensionless Personalized URLs - MVC? - c#

My client has asked me to build a personalized URL system so that they can send out really short URLs in postcards to customers like this:
www.client.com/JasonSmith03
www.client.com/TonyAdams
With these URLs, I need IIS 6 to trap the incoming request and pass that “JasonSmith03” token to my database to determine which landing page to redirect them to.
I’d love to use an HttpHandler or HttpModule but they both look like they require an file extension (.aspx) in the URL. Wildcard mapping will chew up every incoming request and that’s ridiculous. ISAPI filters are just text routing files, so I can’t employ logic to call the database. According to Scott Guthrie, this would be cake if I had IIS 7, but I don’t.
Can this be done using MVC? I’ve been working with MVP for the last few years, so I haven’t done any MVC and routing. I thought I remembered that MVC has the ability to use REST-style extensionless URLs. I’d be more than happy to have these personalized URLs land on a site that’s built in MVC, if it will work.
Thank you!

You may want to look at URL Rewriting. Also the project URL RewritingNet. I've used that project before to do exactly what you need.

Related

ASP.Net MVC Allow Subdomains in URL

This is a different question than the one here: Is it possible to make an ASP.NET MVC route based on a subdomain?
I'm not looking to reroute based on subdomain, I just want to be able to include a subdomain and end up in the same place.
user1.mydomain.com should go to the same place as user2.mydomain.com
I can pluck the subdomain from the request to use it.
Currently a request to foo.localhost returns a 404 error.
Help would be much appreciated.
You can do this at the web host level. It's called site bindings in IIS, I'm not sure what Apache calls it.

Building urls with SessionID in ASP.NET MVC

Is there a way to build urls for an action in-lining the SessionID in ASP.NET MVC ?
I need to build urls that will be used by others clients apps which need to download some kind of data but identifying the original session and I would like to have a self-contained url to do that.

Workflow required to support vanity urls in iis and asp.net

Can someone please walk me through the workflow required to support vanity URLs using IIS 7 and ASP.NET 4.0? What I want to do is be able to handle a request from the browser such as http://john.mysite.com and have it go to and execute my page at http://www.mysite.com/mypage.aspx?id=3. Of course the id would change depending on the url. http://zack.mysite.com might go to http://www.mysite.com/mypage.aspx?id=4.
What I am thinking is I need a database that holds the id's for zack and john and then I would implement a URL rewriter that would rewrite the url to the actual page (e.g. http://www.mysite.com/mypage.aspx?id=4).
Can someone please tell me if I am on the right track here?
Yes I do believe this can be achieved using the IIS URL rewrite module. Note that ASP.NET does support some custom routing too.

Route all page requests to one class in ASP.NET

I'm trying to make an application that can host multiple ecommerce front ends, so I need to figure out how to route all requests to one class which then parses templates and handles all output.
So my question is then how do I route all requests to one class?
In PHP I would use mod_rewrite and have all requests go to index.php and add "main = new MainClass();", but I have no idea on how to achieve this with ASP.NET
The MVC framework isn't what I'm looking for, since I will host several domains with one system.
It sounds like what you want is an HttpModule. (Sorry for the Google link, but there's a lot about this out there and I'm not sure which is the best resource for you.)
Essentially, what an HttpModule does is intercept requests between the web server (IIS) and the application (ASP.NET).
You can use the Route class to register route handlers for all of the routes you define. Basically, you would create one instance of an implementation of IRouteHandler (or different instances of the same type) for all the permutations of the urls on your site.
Also, it should be said that following statement that you made is misguided:
The MVC framework isn't what I'm
looking for, since I will host several
domains with one system.
Any problems or limitations you would run into hosting several domains in one system with MVC will be apparent in ASP.NET as well; MVC sits on top of ASP.NET, not separate from it.

Implement restful url in .net where service is implemented using IHTTPHandler

I want to implement a restful service in ASP.NET. I want it to be compatible with .Net 2.0 and IIS 5+. I am constrained to not use ASP.NET MVC or REST starter kit. By reading on internet I have learned that it can be implemented using HTTPHandlers. The problem is, the request will come in as a POST request. And I want to URL to be like:
http://abc.com/MyService/MyMethod1/
and
http://abc.com/MyService/MyMethod2/
Any workarounds for this?
Thanks,
Vamyip
Your best option is to use URL Rewriting. This is non-trivial in IIS5. The methods I know of are as follows:
Method 1 - ISAPI filter
These are low-level modules that allow you to manipulate the incoming request. Programming one of these is hairy and tough to debug. If you go this route, you are better off using one that has already been built like ISAPI_Rewrite.
Method 2 - IHttpModule
These are managed ASP.Net modules that are easy to add/remove from your application. Again, you are better off using a pre-built component like UrlRewriter.NET. The issue with using one of these, (as BrainLy mentions), is that you have to configure IIS 5 to map all incoming requests to ASP.Net as follows (link):
Open Up IIS and Navigate to the “Home Directory Tab”
Select “Configuration”
Click “Add” and enter “C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked.
One interesting thing to note is that ASP.Net is itself an ISAPI module :)
Once you are able to manipulate URLs using one of these tools, you can easily rewrite the RESTful urls to be handled by your default.aspx page (or whatever handler you choose to use).
If you can allow the restriction of only IIS 7.0 and above you could use URL Rewrite http://www.iis.net/download/URLRewrite to do that pretty easily.
Can I ask why is it that you need to support IIS 5+? That is an 11 year old technology that hopefully people will move out of those platforms in favor of more recent versions. Also keep in mind support for some of those platforms is ending pretty soon.
If the concern is developers running Windows XP I would point out that IIS Express includes version 7.5+ functionality and is available for all platforms Windows XP and above.
I think this will be difficult to do because IIS 5 will not let you handle non ASP.NET file extensions without some additional configuration in IIS. That means you are limited to URLs ending in .aspx etc. To handle URLs like those in your examples you need to map ASP.NET to handle all URLs in IIS, implement some type of URL rewriting, or introduce some kind of hacky 404 redirection.
Once you have the correct mapping in place you can wire up an IHttpHandler, but you will have to parse the incoming request yourself to work out which is /MyService/MyMethod1/ and which is for /MyService/MyMethod2/. If your methods are simple then it is easy to do this with a regular expression.
You should start with a simple handler like this one.

Categories

Resources