Need to give user their own page domain.com/user

Discussion in 'ASP.NET / ASP.NET Core' started by blabberblog, Jul 30, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have users that create accounts and when they create an account they get their own page generated dynamically. So the user has a userID in the db so it works like this:

    Let's say John created an account and his user id is 10. His page would be accessed like this - www.domain.com/userpage.aspx?UserID=10

    Now, what I would like to do is have John be able to access his page like this:
    www.domain.com/John

    There are alot of sites that do this.
    Does anyone know how to do this?

    Thanks,
    Pete
     
  2. quote:Originally posted by Scott

    I believe this article will give you the information you need:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp

    This url was previously posted to DASP by another member in response to a different topic.
    </blockquote id="quote"></font id="quote">

    You might also want to look at .text, a blogging engine for .NET. It has that sort of functionality built in www.gotdotnet.com/community/workspaces/workspace.aspx?ID=E99FCCB3-1A8C-42B5-90EE-348F6B77C407
     
  3. Thanks,

    According to everything I looked at. I still have to create a folder and a default.aspx file inside the folder for every user. This could result in thousands of folders. I there any other way?

    Thanks,
    pete
     
  4. Did you read all of the URL Reqriting article? Aside from that you gave the example:

    www.domain.com/userpage.aspx?UserID=10

    So in reality there doesn't need to be a userpage.aspx file at all. In your site's main Default.aspx in Page_Load just check to see what the requested URL is, say:

    www.domain.com/John

    then look up in a database to find that "www.domain.com/John" equals "www.domain.com/userpage.aspx?UserID=10".

    URL Rewiting in a custom HTTP handler gives you even more flexibility but the above is easy to do. The down side is that the user's browser would then show the latter URL but I believe there is a way to work around that, perhaps someone else knows. For sure though, URL rewriting would solve this too which is why pjoyce recommended it.

    Would that work for you?
     
  5. Strike this line from above I was thinking something else. <s>So in reality there doesn't need to be a userpage.aspx file at all.
     
  6. OK but it doesnt work here's why:

    Lets say we have www.domain.com/userpage.aspx?UID=10

    and we want the user to be able to do type in this:
    www.domain.com/john

    So, in the
    Application_BeginRequest(Object sender, EventArgs e)

    we put code in there to check the url and search the db for the user john and we use Context.RewritePath( "../userpage.aspx?UID =" + nUID);
    to rewrite the URL to what it should be

    The problem is that when the user enters:
    www.domain.com/john
    Application_BeginRequest never gets called. This is because IIS thinks /John is a folder and since it cannot find a John folder with a default.aspx file inside it, then it throws error 404.

    The only way around this from what I can see, is to create a folder with a default.aspx file in it for every user.

    Thanks
    Any other ideas would be appreciated.

    Pete
     
  7. Hmm good point. Interesting problem.
     
  8. I do have a new suggestion. You could use the DASP IIS Manager and create an additional default extension .Login and IIS should pass the request on to ASP.NET.

    So the user would type www.domain.com/John.Login Kinda cheesy but it could keep you from having to do the new folder for each user thing.

    I have not implemented the URL re-writing thing, I feel it's too .NET dependent. If I ever want to move my code to another platform it's just more work. What I DID implement is that if you go to one of my in progress sites, www.solidrun.com for example, you aer really being served from my main site www.mccomsoft.com and the solidrun subfolder there.

    Response.Redirect paired with domain masking is how this works.
     
  9. This is very easy to do....

    You can have www.SomeDomain.com/Default.aspx?name=JimmyBoyBobbyJoeJangles

    Converted to www.SomeDomain.com/JimmyBoyBobbyJoeJangles

    1. First you need an Global.asax file:
    Insure this code is present:
    May be a better way but it works for me.



    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)


    Dim myContext As HttpContext = HttpContext.Current





    Dim currentPath As String


    currentPath = Request.Path.ToLower()








    If System.IO.Path.HasExtension(currentPath) = False Then


    currentPath = System.IO.Path.GetFileNameWithoutExtension(currentPath)


    Try





    'see if we need to rewrite the URL


    myContext.RewritePath("Default.aspx?name=" &amp; currentPath)








    Catch ex As Exception


    Response.Write("ERR in Global.asax :" &amp; ex.Message + Constants.vbLf + Constants.vbLf + ex.StackTrace.ToString() &amp; Constants.vbLf + Constants.vbLf)


    End Try


    End If











    End Sub


    2. Have DiscountASP add the wildcard mapping to point to asp.net


    All set


    Test: www.cthere.com/Stewsterl
     
  10. I do exactly this with my site. Here's my trick:

    I actually put the URL rewriting stuff in my 404 page. That way, when someone goes to:

    mysite.com/user

    The 404 page will pick it up and can Server.Transfer them as necessary. Make sure to have your 404 errors mapped appropriately.

    My 404.aspx.cs page looks something like this:

     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page