3

I'm working on a website in aspx where a user can go to a url similar to "www.website.com/referralname" or "www.website.com/otherreferralname" and will be redirected to www.website.com/genericform.aspx?referral=referralname

I'm not the original designer of the site, and I'd like to add as little as possible, so I'm hoping there's a way to do this through the webconfig, rather than having to add a redirect page and switch case every possible referralname.

I've explored the possibility of using

<customErrors mode="RemoteOnly">
    <error statusCode="404" redirect="~/404.aspx"/>
</customErrors>

But there is already code in the AppCode that somehow is overriding or supplanting mine, and anyhow it only shows the default 404 page. Any advice is greatly appreciated.

Edit: I've been informed that a .aspx won't work with the customErrors tag there, so that might be part of the problem. I'd also appreciate clarification on that issue as well. I will be learning a lot today!

Edit 2: So after doing a little more research, I think the search term that would have benefitted me is "Routing". I've found this MSDN page which I think will lead me to my solution. If this works out for me, I'll post a comment with the "answer" later.

Christine
  • 59
  • 7

2 Answers2

2

You can lookup IHttpHandler and IHttpHandlerFactory. I use them on my wiki. I have pages that end in .wiki and do not exist, but get redirected to generic pages that load them from a database. You have to have access to the IIS server (or call your ISP) to get non-existent files by the extension you choose to still pass through to the Asp.Net software to get handled by it.

There are other ways of doing the same kinds of things.

PS To use my method, I had to have Full Trust on my server to get it to work. I'm convinced that it isn't necessary, but I couldn't figure it out.

Edit:

These are the bookmarks I have saved:

Serving Dynamic Content with HTTP Handlers

How To Create an ASP.NET HTTP Handler

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
  • I've been going over this article about IHttpHandler and IHttpHandlerFactory: [link](http://www.developerfusion.com/article/4643/implementing-http-handlers-in-aspnet/) But it's a little fast and loose, so if you know of any more detailed information sources, that would also be helpful. (Sorry that I had to edit this comment 3 times, I'm still kind of new!) – Christine May 24 '11 at 18:52
  • @Christine I added some links to my post you can review. – Chuck Savage May 24 '11 at 19:05
1

Okay, so the thing that eventually ended up working was the following code added to the system.web area of the web.config folder

<urlMappings enabled ="true">
    <add url="~/referralname" mappedUrl="~/custom/sign-up.aspx?ref=referralname"/>
</urlMappings>

So simple, yet so elusive! I hope this helps others!

Christine
  • 59
  • 7