IIS URL Rewrite - include title in URL based on ID - asp.net

I have an ASP.NET e-commerce application in which product URLs are primarily of the format
<domain_name>/ProductCatalog/Product.aspx?ID=30
I am using IIS URL Rewrite to successfully write this URL as
<domain_name>/ProductCatalog/Product/30
Let's say the product name is "XYZ Item" for ID = 30 in the database, then I would like to do the lookup and rewrite the URL as
<domain_name>/ProductCatalog/Product/XYZ-Item
I am not sure how to go about this? Please point me in the correct direction.

Related

How to mask url from siteA.com to retreive data from siteB.com/page1.aspx?id=1234 - ( IIS - URLrewrite - ARR)

Let say the situation is
User type "http://siteA.com" without pagename or querystring in the browser's address bar then click "Go"
IIS receives the request and redirect it to "https://siteB.com/page1.aspx?id=1234"
IIS receives the response from "https://siteB.com/page1.aspx?id=1234"
IIS rewrites the url to "http://siteA.com/home" so users will see this url in their address bars.
At this state, any links on "http://siteA.com/home" must have http://siteA.com as domain name in URLs. Users should see the links like below links
http://siteA.com/page2.aspx
http://siteA.com/page3.aspx
page1.aspx, page2.aspx, and page3.aspx are actually hosted on https://siteB.com
How many rewrite rules do I need? How to write those? How to set up ARR? Any working examples would be helpful.
You asked a lot of questions at once, but in summary, you don’t know much about URL rewriting. So I suggest you take a look at the Microsoft documentation: URL Rewrite Module

Track Funnel to Shop Main Page

Say I have a website where the main page is mydomain.com/
Then I have a shop subdomain where the main page of the shop is shop.mydomain.com/
I have set up cross domain tracking and that's working fine. I'm a bit confused about how to track the following as a funnel:
mydomain.com/ -> shop.mydomain.com/
Since the funnel setup doesn't consider the domain and the path is both /, wouldn't GA see this as the same page?
If you'd like to see the domain name as well as the Request URI in your reports, create an Advanced filter for your view with the following settings:
Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: $A1$B1
Source

How to obtain urls with descriptive content

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.

Keeping original HTTP_HOST when Redirecting/Rewriting

I am experiencing an issue with the IIS Rewrite Module and nopCommerce.
Situation:
I have several domains (Domain1.ca, Domain2.ca, etc.), each redirecting to a main domain (MainDomain.ca) at the Registrar level (using a CNAME record). Is it possible, using the IIS 8 Rewrite module, to retain the original HTTP_HOST value of the domain originally browsed to (Domain1.ca, Domain2.ca, etc.) instead of the redirected domain (MainDomain.ca)? I need this for the following reason:
In nopCommerce, each store corresponds to a unique domain (Store1 = Domain1.ca). To determine which store is active, nopCommerce obtains and resolves the "HTTP_HOST" value.
Unfortunately, since all domains get redirected to the main domain (MainDomain.ca), the original HTTP_HOST value (Domain1.ca) is lost. Therefore, not knowing which specific store needs to get activated, nopCommerce activates the first one in the list.
I assume that when a site has been redirected to, the original HTTP_HOST value is overwritten.
Does anyone have any experience with nopCommerce, HTTP_HOST, multi-store, domain redirection?
a CNAME does not perform any redirection.
A CNAME simply says that domain1.com will us ethe same dns records as domain2.com, aka it is an alias.
So if you are really are redirecting from your domain registrar then you are not using a CNAME record to do this. You must be using a REDIRECT service at the registrar, the most common one is an FRAME redirect, where they create a website for domain1.com and inside they put a frameset which points to domain2.com
I would suggest that remove this, and just use the CNAME only and then do the redirect at your webserver using URL REWRITE, this will then allow you to retain the original host name.

How to Handle Domain name in MVC Routing

I am trying to use routing to redirect my user to another URL, if he enters my website through the IP address.
Or if possible please tell me if it possible to handle domain name by routing. As I can use routing for Controller and for Action, but can I also handle Domain in there or not?
I am currently using it like following, but I am unable to handle Domain:
routes.MapRoute(
"Controller",
"Controller/{action}/{id}",
new { controller = "Controller", action = "Index", id = UrlParameter.Optional });
If you're using IIS 7, it may be better to implement this at web server level.
This way, the proper status code will be returned to the browser in the HTTP header and your MVC app can deal with its own routing without having to worry about domains and hostnames which, in most cases, is the web server's job.
To achieve this on IIS, open your website in the IIS console and select URL Rewrite and follow these steps:
Create a new rule and set the match URL to wildcard and enter the pattern as the IP address as xxx.xxx.xxx.xxx*
Add a condition where {HTTP_HOST} is equal to the site's IP address.
Set the "action type" to redirect, and enter the pattern you wish to redirect to. "http://mysite.com{R:1}" in this case would map everything after the IP address to its domain equivilent, so xxx.xxx.xxx.xxx/mycontent would redirect to mysite.com/mycontent
This approach will ensure your subdirectories are mapped and your site remains search engine friendly, with proper response codes being generated.
The screenshot below shows how your rule might look in IIS:
Alternatively, this question on ASP.NET MVC Routing by Subdomain may be useful if you need to do this within the confines of your app.

Resources