Rewrite url using global.asax

I am trying to make some friendships in my vb.net project (.net 4) and I am trying to do it using something I read about global.asax and Application_Beginrequest, but I cannot compile it.

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    Dim httpContext As System.Web.HttpContext = httpContext.Current
    Dim currentURL As String = currentURL.Request.Path.ToLower()
    If currentURL.IndexOf("widgets") > 0 Then
        objHttpContext.RewritePath("products.aspx?ID=123")
    Else
        objHttpContext.RewritePath(httpContext)
    End If
End Sub

      

Above, this is what I am trying, but this is a bug on objHttpContext. is there any other method? Ideally, when I get the above method to work, I am going to use a database call to design urls. Therefore, any proposals in this direction will also be very welcome. I am trying to get away from having to install anything in IIS as this is a load balanced environment that I would not want to install on every server.

thank

Tom

+3


source to share


2 answers


Why would you want to use rewrite when you can do it very easily using asp.net routing?



Please see the following link for more information: http://msdn.microsoft.com/en-us/library/cc668201.aspx

+1


source


You should refer to HttpApplication.Context. This is how I do it (C #):

string reqPath = Request.Url.AbsolutePath;
if(reqPath=="/")
    newPath="/Pages/PL/Main.aspx";
if (newPath != "")
    HttpApplication.Context.RewritePath(newPath);

      



As I see in the documentation, you should be able to use exactly the same syntax to access the context in VB.NET.

You can also use the II7 url rewrite module if you like.

+7


source







All Articles