How to construct expandable website structure? - asp.net

HI,
I have a ASP.NET webiste I created from craft and it now look a big mess. I want to reorganize this but don't know the good way to do it. Some first look well but later cause trouble with master page, image path...
Now I'm thinking of 2 ways:
Using UrlWriter: but it seems lead to a bulk of path rewrite and usually lead to Resource not found or something
Using a page as main entry and using Server.Tranfer to pull the right page content, despite of its location
Which is better? Do you have another method?
Please help!

There's another approach, System.Web.Routing, added in ASP.NET 3.5 SP1. Basically, you implement the IRouteHandler interface and manually route the request to an appropriate handler.
This is how ASP.NET MVC handles request routing. There's a guide here that uses it for Web forms.
By the way, consider looking at ASP.NET MVC and check if it's appropriate for your situation.

Related

Use asp.net routing on top of old asp system

I'm experimenting with using MVC routing as a temporary fix to get SEO friendly urls on an old (VB6/ASP classic) system while it's being re-written (which will take a long time).
The old system has 1 asp file with a vb6 dll that generates html which is served by a response.write in the master.asp.
so urls on that system look like this:
www.foo.com/master.asp?sessionid=abc123&pagetype=Item&ItemID=My-widget
I'm wondering if I can use an MVC project to create a route for cleaner urls
and have a controller map the values and build the corresponding old url and then do a Server.Transfer to it.
So the new url would look like:
www.foo.com/Item/My-widget
and map to the old url at
www.foo.com/master.asp?sessionid=abc123&pagetype=Item&ItemID=My-widget
both could then be used interchangeably so the existing site doesn;t have to change, but I could use the new cleaner url on external sites for better SEO
Is this possible?
Is there another way to do this?
edit:
since it's not possible to use server.transfer from MVC, I'm now considering using routing in an ASP.net webforms app.
This should allow me to get the routing part of the application done. Will post back here once I've tried it.
I would suggest you use UrlRewriter.net library instead. It has a lot more features than the the built-in Routing framework (including Regex support), support for permanent redirects, and it's all configurable in the web.config file.
I've tried to use Routing before for this sort of thing but found that it became quite limiting very quickly.
http://urlrewriter.net/
Edit: you will still need a .net web project "wrapper" for your classic asp solution though, as you describe in your question, which of course comes with it's own problems as outlined in the other answers.
I cant think of a way that you could do this, but you might have some luck with the url rewriter module in iis: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
I think this could be made to work, but it doesn't sound ideal. I suspect you'd run into some issues with sharing data between the two sessions too. It may be a good idea IF you are planning to migrate to .net, and the app will be running in a "half and half" state for a while (if so I'd suggest introducing a managed core library shared between both sides before worrying about url rewrites).
I haven't done much work with classic ASP lately, but I think this post on URL Rewriting in Classic ASP might be helpful to you.

How can one build dynamic sitemaps in ASP.Net?

How can one build dynamic sitemaps in ASP.Net?
Sql Sitemap Provider
Physical file sitemap provider
You can take a look at these for ideas or just reuse them.
Not sure about your exact context (Forms or MVC, etc), but here are a couple of resources you can take a look at. You have several options, and I don't yet have the rep to post multiple links, so I'll post the google search link I did and call out a few links I found that could work for you.
http://www.bing.com/search?q=ASP.NET+Dynamic+sitemap&form=QBRE&qs=n&sk=&sc=1-23
Scan your site folder structure (using LINQ) and auto-gen a sitemap - 3rd Link (Creating Dynamic ASP.NET SiteMap using LINQ)
Implementing your own SiteMapProvider (MDSN) - 6th link (Implementing ASP.NET Site-Map Providers)
Implement and override the StaticSiteMapProvider - 4th Link (Adding dynamic nodes to ASP.NET site maps at runtime by deriving from ...)
SiteMapProvider for MVC - mvcsitemap.codeplex.com
Simple implementation using RouteTable values (MVC) - 10th link (Dynamic sitemap in ASP.NET MVC - Stack Overflow)
I hope these help, or point you inthe right direction. Feel free to comment with more details if you're looking for something more specific.

Can someone give me an overview of ASP.net and how it's different from technologies such as php?

I've been doing the html and css for a site, sending it off to a guy to implement in a web server. I get a call from the designer freaking out about the progress, saying the clients aren't happy. He wants me to personally integrate my css with what's on the site. The site is done in ASP.net, time is short, and I'm a little in over my head. I have an understanding of how php works, but have never worked extensively with it.
Looking at the stuff on the ftp, I can't even find equivalent of the index.html file (I know that when I go to the site itself, there is nothing after the base url, i.e., www.site.com/ brings me to the homepage.)
Can anyone give me a few tips or links as to what I am to do with this, or where to even being navigating this site?
EDIT: It's -not- a .Net Web Application, from the looks of it.
ASP.Net can be run in a compiled or a scripted environment. It is important to understand which environment your client has. If it is completely scripted, then you are likely looking for the default.aspx file and it's contents. If it is a compiled environment, you may be in for a ride. A compiled site may incorporate "master pages" as a templating engine, and then you'll need to apply your html/css modifications in several places.
You should start with the default.aspx page if there is one. Look for master page directives (it'll be named something like masterpage.master). If there isn't one, then you're in luck you'll just need to implement your changes on a page by page basis. The aspx page will be in a templated xml format so avoid touching tags that involve touching
If you are making changes to divs and structures of that nature, you may need to modify the CssClass attribute of the controls. I would recommend however that you make a back up, give it a shot, and under no circumstances attempt to do something that you aren't really ready to do. You will only anger the client and ruin your rep. It may actually be prudent to contact an actual ASP.Net developer to analyze the files separately and determine what you need to do.
I suggest that you read the Wikipedia article about ASP.NET to get familiarized with it as it summarizes the basic building structures.
Then, just to get you started: take a look at the more recent ASP.NET MVC (Model-View-Controller) paradigm. There's also development in what is called ASP.NET WebForms.
For example: when you go to www.site.com/ (known as friendly URLs) it may be redirecting you to an action method inside a controller. It's called routing. There's also URL rewrite.
In the MVC world a Controller can send/redirect the user to a specific View/Page.
A View (.aspx form/page) that contais HTML markup and CSS on the server side is basically an HTML page (.htm) page that'll be rendered on the client side.

How to SEO friendly an existing ASP .NET 3.5 web application under IIS6

So, I know there's a lot of this subject here and over the Internet. But most articles/questions refers to "static" url rewriting, like:
www.site.com/products.aspx?category=Books
So they rewrite it to
www.site.com/Products/Books
That's ok but I need something else.
The site is like a CMS, it has different types of content.
Nowadays to read the article titled "How StackOverflow helps you in your development" you need to go to an URL like the following.
www.site.com/viewContent.aspx?Id=1234
What I want to achive is:
www.site.com/Content/Articles/how-to-stackoverflow-helps-you-in-your-development
So as I understand, I need to involve ASP .NET in that, because first I need to retrieve the article (an its title of course) and then rewrite the URL.
But I'm wondering how the hell ASP .NET will know how to get that article if I go to that URL, it doesn't include the id anywhere...
So maybe I could accept something like
www.site.com/Content/Articles/1234/how-to-stackoverflow-helps-you-in-your-development
I'm kind of lost here really.. I've never done any URL Rewriting at all and I've googled a lot and I cannot find a way to do what I want. Maybe what I want is not called url rewriting??? I don't know...
The site is running under Windows 2003 Server, IIS6, ASP .NET 3.5 SP1
And of course, I need a free solution, cannot spend 100usd on the ISAPI mod (besides I don't know if that is going to do what I need).
Thanks to all and sorry if this is a duplicated question, but I couldn't find it.
EDIT: I don't need to support non-ASP.NET files (jpgs, gifs, etc) don't need to be rewritten. I just need to rewrite the viewContent page to include the content title into the URL.
You can use the new Routing that comes with ASP.Net 3.5 sp1 to have clean URLs.
This can even be done in web forms and not just MVC. ( I have done it myself). See here and here for exanples of how to set it up.
You can throw the Id of the article and the title in the URL and make the Id the real parameter that gets used to search for the article. That is what SO does. Try removing the question for the URL and it will take you to the same place.
Even if you don't use the Id you can pass the title of the article "how-to-stackoverflow-helps-you-in-your-development" to your DB and retreive the article based on the title.
With regards to IIS 6 it is a little trickier since IIS 6 by default can't handle extension-less URL's.
There are a few work arounds:
Use the wildcard mapping in IIS to map all requests to Asp.Net
Put Default.aspx at the end of your urls
See this post for other possible solutions.
Although the first solution may have performance issues if all content in your site goes through Asp.Net (even images, css, .html ...) in a small site it shouldn't matter. I have used this approach and there wasn't any major performance issues. I think it is the simplest solution. Here is the website I built with it
I hope this helps.
This one is free, I have used it and it works pretty well: http://www.codeplex.com/IIRF
The nice thing is that it will handle url's without an extension (i.e. .aspx, .html, etc.)
You can achieve this with ASP.NET routing.You can do this with ASP.NET MVC as well as Webforms.No need to do anything with IIS.
Check the below link
https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink
I did URL routing in my web application within 1 hour with the details from the above link.Its quite simple to learn .They provide sample codes too.It will help you to do it easily
You can retrieve the Id of the content using the title.But title should be unique.You can use ajax to check whether the title is a already existing one when user takes mouse out from the textbox.
Easiest way is to add a http module to your current webforms project.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This shows you the basics of it, But it can easily be expanded so that the pages you want to rewite is taken from a database or even built on the fly.
ASP.net MVC is your friend for that
stackoverflow use MVC

ASP.NET webpages without names, like stackoverflow?

Mentioned stackoverflow only as an example, but if you look above the URL for ask is
http://stackoverflow.com/questions/ask
which means /ask is a subdirectory, but they also do this for the specific question pages. How do you code this in .NET?
Not a code question as much as a technique. I know this is great for SEO, but how do you create a site so that every "page" is its own directory? Dynamically.
Do you have a template or a hidden redirect???
How?? :)
It's termed URL rewriting:
Url Rewriting with ASP.NET
MSDN: URL Rewriting in ASP.NET
EDIT: As #Justice points out, StackOverflow uses Routing.
StackOverflow uses something called Routing, which comes with .NET 3.5 SP1. Routing is a popular feature of a number of MVC frameworks, such as ASP.NET MVC, Ruby on Rails, and a number of Python and PHP frameworks.
Stack Overflow was built using ASP.NET MVC which uses a technique called Routing, see:
What Was Stack Overflow Built With?
and Routing
Stack Overflow uses ASP.net MVC
MVC uses the URL + Query String to determine the content, so its not like a URL which points to a specific page, but more like a hierarchical path to the properties of some data to be displayed
E.G. https://stackoverflow.com/users/[Put User ID Here]/[Put User Name Here]
prompts the website to display a USER with an ID specified in the path ( in this case the user name is probably just for kicks ) as opposed to a specific page created just for that user.
I have seen this accomplished by simply creating a folder for every web page and then having each folder contain a Default.aspx document (Assuming Default.aspx is setup as a default document in IIS, which it is by default). Then you can navigate to any folder on the site without specifying the page (Default.aspx).
For the dynamic part, I have worked with CMS systems that do it this way and the Default.aspx page simply inherits from some master template and the CMS system utilizes the ASP.NET rendering enginge to dynamically complete the web page.
Using folders may be a little heavy with the site structure, but it is an easy way to eliminate the page names from the browser.
This is how I structure my website and avoid having to use page names... for example http://www.innovaapps.net/Blog simply brings up the default.aspx page without having to specify the page name.

Resources