Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

HttpContext.RewritePath Method Help!!!

Back to Forum: Tech Off
  • User profile image

    I am having the hardest time getting this to work. I have been playing around with the HttpContext.RewritePath Method because I am trying to take this: and make it so when the browser requests this it will return the query string userID... or something similar, I just can't have query strings in the url, it has to look like a directory request.
    Anyway, one of the problems I am having is the HttpContext.RewritePath Method is extremelly poorly documented. (like most other things in the msdn documentation, but that is another rant)...
    Anyway, here is the code I have in the Global.asax file.

    void Application_Start(Object sender, EventArgs e)
        HttpContext httpCont = HttpContext.Current;
        httpCont.RewritePath("~/Redir", "", "");

    You may be wondering why there isn't anything in the other arguments... well that is because I don't know how to use them.

    Anyway, when the ~/Redir/Default.aspx page is requested as such:
    it will get the query string userid=jdale

  • User profile image

    If you don't need Postback functionality here's a quick fix for friendly urls.

  • User profile image

    actually, I do... What is happening behind the scenes is the user will register their domain... ie which will be a redirect to
    when the user request this page they are given a cookie based on the userid which in this case is jdale and redirected to that users content.

    Anyway, I am basically trying to create a redirect to the individual employees personal websites, but if you guys have any other ideas, I am all ears. The problem I was running into was when doing dns redirects the query strings weren't being passed.

  • User profile image

    Make a custom 404 handler for the /Redir/ directory
    Parse the username from the Request.RawUrl (see Adam's code)
    Do a Response.Redirect to the page with the content

    Not sure what you mean by "DNS Redirect" -- you mean, CNAME?

  • User profile image

    No, web direct. I am trying to redirect to specific folders, not just another domain name.

    Edit: but I like your 404 idea, I will have to try that out, that seems like a very good solution. (AdamKinney, sorry if that was in your post, I only browsed, I didn't read it entirelly.)

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.