How to obtain urls with descriptive content - asp.net

Asp.Net Web Forms: I need an advice about handling urls like many news site do.
Example: i've seen that some site publish an article about a soccer match and its url is something like this:
http://siteAddress/soccer/big-match-Milan-Champions-league
In an intranet scenario (that i'm used to) i would have had a table with a numeric id and my url would have been this:
http:/ipAddress/article.aspx?id=345
How can i obtain an url like that?
I know the urlrewrite concepts in asp.net.
Thank you!

ScottGu's article describes several ways to solve this problem: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
On my site, I created an HttpModule (like his 2nd & 3rd approaches). The module calls the database to lookup the article ID that matches the given URL. If a URL is found, then the module calls Context.RewritePath to send the incoming request to the correct page.
If you do this, make sure to cache the database calls. It would be best to not call the database for every incoming request. Depending on how often you generate new content, you could pre-fetch all of the "url to article ID" mappings from your database so that you wouldn't need any database hits to rewrite the URL.

Related

How to receive and process post data from a thirdparty company

I am using a thirdparty credicard processing company. I am sending amount to pay creditcard number etc to them. They said they will postback the results such as confirmation number to a url provided by me. I have to save the confirmation number in my database. Mine is an asp.net web application. I am wondering what will be best way to provide a url. Should I give an aspx page or create a http handler which will process the data from the third party company?
Thanks
Definitely a generic http handler (.ashx), because it's a lot more lightweight than .aspx.
The basic idea: use .ashx when you don't need to display a web page to end user, otherwise use .aspx.
Should I give an aspx page or create a http handler ... ?
Neither, use a WCF service.
WCF service to accept a post encoded multipart/form-data

rewrite url multiple times? multiple tables with urls

(i've asked a similar question earlier, but this is a more specific question, thats why i start a new thread.)
I am at the beginning of a asp.net project where i maybe will use url rewriter. (for the first time)
I have a couple of users who have individual subdomains.. and in every subdomain each user has individually categories, sub categories and pages. so for example, a users webpage could look like:
user1.mydomain.com/category1/sub1/page1
user1.mydomain.com/category1/sub2/page45
user1.mydomain.com/category1/page123
user1.mydomain.com/category2/sub56/page134
as you understand these categoris and pages are dynamic, and i want to use url rewrite.
But due to large amount of users, i dont want one HUGE list of urlrewrites.
So my question is.
Is it possible to rewrite the URL multiple times?
first the web application check for the subdomain, which gives us some ID for the wep page.
user1.mydomain.com/category1/page1.aspx -> users.mydomain.com/category1/page1.aspx?accountID=1
and then depending on the, in this case, accountID checks for the correct "lookup table for url rewrites"
something like:
account1_url_list
account2_url_list
...
To get the correct url for the rest of the "pretty-url", in this case "/category1"
i guess that the web.config file cant handle so many url-rewrites?
And one other question.
What happens with urlrewrite when one of the users points his own domain to his page at my web application?
So that the adress bar in internet explorer, or firefox is something like:
www.user.com points at user1.mydomain.com
am I able to get the correct ID of that user?
Thanks!
Matte
Thanks for the reply.
Unfortionally i am not able to run a url rewrite on the IIS, i think. Only some kind o .net rewriter like
www.urlrewriting.net
I have a question regarding someone pointing his own domainname to my web application.
Is it possible to use the ”user1.”, ”user2” sub domain names to match the user to his account, or do I also have to use his domainname during the process to find his accountID?
Lets say user1 owns a domainname. www.user1domain.com
he points that domain to user1.mydomain.com
so the visible url is www.user1domain.com.
What happens?
Is there some command to find what subdomain his domain is pointing to?
Thanks!
Yes, URL Rewriter supports multiple processing steps, as Eok discusses in his blog entry regarding the processing chain and continuing or stopping processing: http://blogs.iis.net/eokim/archive/2008/06/05/url-rewrite-module-basic-understanding-lt-rule-gt.aspx
The web.config can handle a very large number or rewrite rules (I don't actually know how many, but it might be fun to test!).
If you've got more than say a couple dozen rules you might have a problem that could be refactored and simplified.

ASP.NET - Razor. Rewrite URL on the fly

Is it possible to rewrite URL on the fly, only when a part of the server code has already been processed for the "raw" URL and it becomes clear the parameters must not be revealed to the user? Like, I want to proccess all the GET parameters in my page code on the server and create a tracking record in the database, then serve the user the page but change URL to parameterless in the browser.
I guess all the web.config referred module techniques won't work as they offer URL rewriting before request is passed to the page code on the server. But it comes in my case that I receive an ugly URL from google adwords clicks and I do like it tracked 'as is' in my database, and I do certainly not like it show to user in her brower's bar.
At the same time I would like to keep URL unchanged without applying the URL rewrite most of the time unless some particular parameter shows up in it (like ref=adwords) so that any paramter written by hand or posted back would be displayed in the address bar.
Is it possible to do so by any means?
Have you considered writing an ActionFilter that would (if your controller or method is decorated with it) intersect your initial request, do all the necessary processiong and then redirect back to the requested page only indicating, that processing has been done?
This would be my first thought.

Accessing Jump Links (the part of the URL after a hasch character, #) from the code behind

Anyone know if it's possible to access the name of a jump link in c# code?
I'm doing some url Rewriting stuff and I'm thinking I might not be able to see that part of the URL.
So basically, my URL looks a little something like this:
http://www.mysite.com/Terms.aspx#Term1
And I want to access "Term1". I can't see it in the ServerVariables...
Any ideas?!?!?
THANKS!
The hash character is meant for client side navigation. Anything after the # is not submitted to the server.
From the wikipedia article:
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment.
Its technical name is Fragment Identifier
Perhaps System.Uri.Fragment? Or what is it you don't see?

ASP.NET 404 (page not found) redirection with original parameters preserved

I'm replacing an old web application with a new one, with different structure.
I can not change the virtual directory path for the new app, as I have users which have bookmarked different links to the old app.
Lets say I have a user, who has this bookmark:
http://server/webapp/oldpage.aspx?data=somedata
My new app is going to reside in the same virtual directory, replacing the old one, but it has no longer oldpage.aspx, instead it has different layout, but it still needs the parameter from the old url.
So, I have set to redirect 404 errors to redirectfrombookmark.aspx, where I decide how to process the request.
The problem is, that the only parameter I receive is "aspxerrorpath=/webapp/oldpage.aspx", but not the "data" parameter, and I need it to correctly process the request.
Any idea how I can get the full "original" url in the 404 handler?
EDIT: reading the answers, looks like I did not make the question clear enough:
The users have bookmarked many different pages (oldpage1, oldpage2, etc.) and I should handle them equally.
The parameters for each old page are almost the same, and I need a specific ones only.
I want to re-use the "old" virtual directory name for the "new" application.
The search bots, etc., are not a concern, this is internal application with dynamic content, which expires very often.
The question is - can I do this w/o creating a bunch of empty pages in my "new" application with the old names, and Request.Redirect in their OnLoad. I.e. can this be done using the 404 mechanism, or some event handling in Global.asax, etc.
For the purposes of SEO, you should never redirect on a 404 error. A 404 should be a dead-end, with some helpful information of how to locate the page you're looking for, such a site map.
You should be using a 301, moved permanently. This allows the search bots to update their index without losing the page rank assigned to the original page,
See: http://www.webconfs.com/how-to-redirect-a-webpage.php on how to code this type of response.
You could look into the UrlRewritingNet component.
You should also look into using some of the events in your Global.ascx(?extention) file to check for errors and redirect intelligently. The OnError event is what you want to work with. You will have the variables from the request at that point in time (under the HttpContext object) and you can have your code work there instead of a 404. If you go this route, be sure you redirect the 404 correctly for anything other than oldpage.aspx.
I am sorry I don't have any explicit examples or information right now, hopefully this will point you in the right direction.
POST and GET parameters are only available per request. If you already know the name of the old page (OldPage.aspx) why not just add there a custom redirect in it?

Resources