locked
URL Rewriting with Master Pages and Web Parts RRS feed

  • Question

  • User142551147 posted

     

    Anyone had any experience with this?

    URL Rewriting with Master Pages and Web Parts.

    I have already written an HttpModule for URL rewriting, but when I use it with Web Parts, I get a javascript error, "WebPartManager is undefined".

    If I exclude the HttpModule from the project ( and use the default asp.net httphandler) then the page loads correctly.

    Therefore, I assume that the URL rewriter is messing up the Web parts functionality of my page.

    Any ideas?

    bill

     

    Thursday, February 23, 2006 1:23 PM

All replies

  • User-1634877164 posted
    Hi Bill,

    It could be something specific with your URLRewriter.  Have you checked out this one to see if it has the same problem: http://weblogs.asp.net/scottgu/archive/2006/01/18/435870.aspx

    Hope this helps,

    Scott

    Saturday, February 25, 2006 1:19 AM
  • User142551147 posted

    Thanks Scott. I'll check that out.

    In addition to a url re-writer, I also need to write a custom personalization provider for my web parts.

    Basically, I need to load web parts on a page, based on the url the user enters. Like so:

    http://www.testpage.com/bob

    In this case, the page will need to load the personalized web parts and settings that 'bob' has set up.

    Actually, I'll need to load the page based on the application name ('testpage') and the user ('bob')

    Visitors to the site will not be able to edit anything at all, just view the page.

    'Bob' will change his page by logging into an admin page and make and save his changes there.

    I think the easiest solution would be to create a class that inherits from 'Sqlpersonalizationprovider' and override several of those methods.

    Any suggestions?

    bill

    Saturday, February 25, 2006 4:54 PM
  • User331136620 posted

    One thing to look at would be this post: http://forums.asp.net/1211536/ShowPost.aspx

    I didn't outline it, but I think you could also override the same set of methods, but instead keep things always running in per-user scope.  And in the overrides change the "path" parameter to reflect a combination of appname and username.

    The post above keeps all the data in the per-user personalization table and fakes out the personalization infrastructure to think it is getting shared scope data.

    If instead you treat each combination of page + appname + username as a unique "page", you can also get the behavior your are looking for.  With this approach you will end up with lots of rows in the paths table because of all the user/app specific pages will get registered there.  Then you can grant all authenticated users rights to enter shared scope.  So each individual user can then enter shared scope on their unique page.  And anonymous users will see the shared scope view of the page - but won't have rights to actually modify anything. 

    Monday, February 27, 2006 7:29 PM
  • User142551147 posted

    Thanks alot. That really helped out alot.

    However, I'm still trying to figure out how I can get the Url Re-witer to work.

    I have an httpModule that does work when you don't use master pages or web parts.

    My Url re-writer seems to be breaking web parts. I think there is a property/method/event that I am not accounting for.

    What am I missing here?

    Tuesday, February 28, 2006 10:49 AM
  • User142551147 posted

    I also found this post:

    http://forums.asp.net/770875/ShowPost.aspx

    But I think the webpartmanager is not looking at the correct url.

    I've created a provider that inherits from SqlPersonalizationProvider and overrides the methods listed in the above article. Here's my code for the LoadPersonalizationblobs:

    Protected Overrides Sub LoadPersonalizationBlobs(ByVal webPartManager As WebPartManager, _

    ByVal path As String, _

    ByVal userName As String, _

    ByRef sharedDataBlob() As Byte, _

    ByRef userDataBlob() As Byte)

    'userDataBlob gets filled

    'get the username

    userName = "admin"

    'Swap the sharedDataBlob and userDataBlob around to get the

    'user specific data for the web parts

    'I think I need to set the webpartmanager.page.request.rawurl property, but it is Read Only

    MyBase.LoadPersonalizationBlobs(webPartManager, path, userName, userDataBlob, sharedDataBlob)

    End Sub

     

    Tuesday, February 28, 2006 11:27 AM
  • User331136620 posted

    We save data based on the value of Request.AppRelativeCurrentExecutionFilePath.  If you want to use a different path, you can set the path parameter in your provider's method override to a different value and the SqlPersonalizationProvider will use that value.

    The webPartManager parameter is there mainly for easy access to the page and context if needed by a custom provider.  The SqlPersonaliationProvider doesn't use it though - it only looks at the userName, and path parameters.

    Tuesday, February 28, 2006 2:40 PM
  • User142551147 posted

    Here is the order in which the events fire off:

    'Rewrites the URL to point to the page with the master pages & web parts:

    Protected Overrides Sub Rewrite(ByVal requestedPath As String, ByVal app As System.Web.HttpApplication)

    'Loads the Personalization info for a user

    Protected Overrides Sub LoadPersonalizationBlobs(ByVal webPartManager As WebPartManager, ByVal path As String, ByVal userName As String, ByRef sharedDataBlob() As Byte, ByRef userDataBlob() As Byte)

    'Then it does something I am not familiar with. It passes in WebResources.axd to this method again...

    Protected Overrides Sub Rewrite(ByVal requestedPath As String, ByVal app As System.Web.HttpApplication)

     

    As a hack I had to put in this statement to stop it from re-writing the URL for WebResources.axd:

    If Not (dealerName.Contains(".axd")) Then

       'Point them towards the real URL

       HttpContext.Current.RewritePath("~/dealer/default.aspx", True)

    End If

    The 'WebResources.axd' is some kind of client-side scripter that writes out javascript I think.

    Is there a better way around this Hack?

    bill

     

     

     

    Tuesday, February 28, 2006 4:54 PM
  • User331136620 posted
    For webresource.axd - just special case this Url and ignore it - i.e. don't rewrite anything, just immediately exit from your custom module.  For rewriting Urls where you are inspective every inbound path this is really the only way around it.
    Tuesday, February 28, 2006 5:50 PM
  • User1607943671 posted
    Thankyou, I had been having problems with this for a long while. Your post finally helped me fix it.
    Monday, February 12, 2007 4:26 AM