locked
how do i do url rewriting this way..? RRS feed

  • Question

  • User312020517 posted

     hi all,

    can anyone guide me on how to use this way of doing url rewriting?

    i'm referring to the http://msdn.microsoft.com/en-us/library/ms972974.aspx the part about 

    using

    <RewriterConfig>
    <Rules>
    <!-- Rules for Product Lister -->
    <RewriterRule>
    <LookFor>~/Products/Beverages\.aspx</LookFor>
    <SendTo>~/ListProductsByCategory.aspx?CategoryID=1</SendTo>
    </RewriterRule>
    <RewriterRule>
    </Rules>
    </RewriterConfig>

    please help

    thanks  

    Tuesday, July 17, 2007 9:57 PM

All replies

  • User-520527587 posted

    In my humble opinion this is one of the best explanations of URL Rewriting out there. I recommend going and reading it and if you have any more questions about it after reading this article. Please ask away.

    http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

    I hope that helps,

    Brendan 

    Tuesday, July 17, 2007 11:03 PM
  • User312020517 posted

     hi there brendan,

     in one of the code sample scott demo-ed

        void Application_BeginRequest(object sender, EventArgs e) {

            
    string fullOrigionalpath Request.Url.ToString();
            
            if 
    (fullOrigionalpath.Contains("/Products/Books.aspx")) {
                Context.RewritePath(
    "/Products.aspx?Category=Books");
            
    }
            
    else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) {
                Context.RewritePath(
    "/Products.aspx?Category=DVDs");
            
    }
        }

     

    somehow i got this error for teh Request.Url.ToString();

    Request is not available in this context 

    Wednesday, July 18, 2007 1:39 AM
  • User312020517 posted

    sorry about that it was a mistake on my part its working...

    only that...

    not really the way i want it to..

    i have 2 pages

    a login and a sort of unauthorized.aspx page

    every page in my website will redirect the user to the unauthorized page where there is a timer that counts down from 5 secs and redirecting the user to the login page after 5 secs has elapsed.

    so..i couldn't do a server.transfer() to the unauthorized page because some error will occur when the timer ticks and does a asyncpostback so...

    what i wanted to do was..have the unauthorized page come up but the url will be displaying the login's url...if i do it the rewritepath way..i realise that i lose my unauthorized page and its also affecting my ability to login...

    any idea how to work around?or is the best way just to give the unauthorized page a nice name? lol 

    Wednesday, July 18, 2007 2:14 AM
  • User-240370940 posted

    Hi  shadstrife,

    somehow i got this error for teh Request.Url.ToString();

    Request is not available in this context 

    AFAIK you must define the current context like this

    1    HttpContext context = HttpContext.Current;
    2    // get the url as String
    3    string urlString = context.Request.Url.ToString();
    
    Correct me if i'm wrong.
     _______________________________________________________________
    As i worte this, your last post was'nt up. Forget it.
    Wednesday, July 18, 2007 2:21 AM
  • User-520527587 posted

    So correct me if I am wrong. You are trying to set up pages that have authorized users not based on being logged in or on some role. If that is the case then if you are using the ASP.NET membership you can just define some locations in the web.config let me know if that is the case.

    If you are not doing that then you will want to write some logic in a base page or a masterpage which can be called by the child or content pages. In this scenario the masterpage contains a method which can be called on init of the child or content pages and it will see if the user is allowed access and if not response.redirect to a no access page.

    It is a simple solution, but if you are trying to just restrict based on being logged in or based on certain user roles that is easy and I will share with you a link with good information on it 

    http://weblogs.asp.net/scottgu/archive/2006/01/31/437027.aspx

    I recommend finding more resources on how to use the <location> element to handle authorization.

    I hope that helps,

    Brendan 

    Wednesday, July 18, 2007 9:06 AM
  • User312020517 posted

     hmmm...not exactly on the spot...right now all my pages can redirect to the no access page without any problems...

    only that..haha it would be preferable  if i can change the url of the no access page to the login page

    like say the no access page is called block.aspx

    so..i want it to display login.aspx instead

    possible?or just too troublesome and easier if i just gave it a nicer name? 

    Wednesday, July 18, 2007 11:42 PM
  • User-520527587 posted

    are you using the location element to perform the redirection to the no access page? 

    Thursday, July 19, 2007 8:58 AM
  • User312020517 posted

     nope...my code is rather ineffective it uses response.redirect.

    and i'm not using the membership roles and stuff because i'm using mysql so i created my own 'authentication' by saving the user type on login and checking on each page he access whether he is the

    correct user type to view it if not the response.redirect will occur
     

    Thursday, July 19, 2007 9:14 PM
  • User-900677162 posted

    HI,shadstrife

    You can Check URL validity by this way:

     

    Public Class UrlValidity

    Public Shared Function IsValid(ByVal Url As String) As Boolean
    Dim sStream As Stream
    Dim URLReq As HttpWebRequest
    Dim URLRes As HttpWebResponse

    Try
         URLReq = WebRequest.Create(Url)
         URLRes = URLReq.GetResponse()
         sStream = URLRes.GetResponseStream()
         Dim reader As String = New StreamReader(sStream).ReadToEnd()
         Return True
    Catch ex As Exception
         ‘Url not valid and redirect to the login page
         Return False
    End Try
    End Function

    End Class

    If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.

    I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

     

    Friday, July 20, 2007 2:19 AM
  • User-900677162 posted

    HI,shadstrife
    We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.
    Thank you for your understanding! 

     

    Sunday, July 22, 2007 10:44 PM
  • User312020517 posted

    hey rex,

    sorry for the super late reply was busy with other work..

    anyways, do u mind explaining what does your code do?

    thanks

    Monday, July 23, 2007 10:39 PM