开发者

ASP.NET - how to change requested page names transparently?

Very new to this subject and under the gun to come up with a solution. The problem is how I could load one of several versions of the same ASPX page, for any given page. E.g. unknown to the unsuspecting user who requests catalog.aspx, I would actually serve one of catalog_1.aspx, catalog_2.aspx, or catalog_3.aspx, etc.

Strange request indeed. It's due to an inherited decade-old product having inlined styles all over the ASPXs. Instead of re-writing the hundreds of ASPXs to be flexible, I'm trying to regexp-replace them to get versions suitable for various screen sizes. I'd then choose the best one after measuring window size at user login (and perhaps store the size in a cookie).

I thought this would involve some lower level object like an http handler. Close?

LJ

Update: I ended up doing this through url rewriting which works much better. The easiest place to do this in asp.net is apparently global.asax, and under Application_BeginRequest event. Call context.RewritePath(newpath, False) to send the request to a different page than requested.

In the way I did it, the destination page can change from request to request, and that apparently upsets postbacks, if the recipient of the postback isn't the exact version of the page that generated the viewstate.开发者_开发问答 I tried to turn off viewstate validation but didn't help. So had to prevent flipping between versions once a user's logged in. Hope this helps someone.


Server.Transfer is probably the quickest way of doing just that.

string TransferTo = string.Empty;

if( Something ) 
     TransferTo = "catalog_1.aspx";
else if( SomethingElse )
     TransferTo = "catalog_2.aspx";
else
     TransferTo = "catalog_3.aspx";

Server.Transfer( TransferTo, false );

Documentation

Note If the subsequent pages have postback controls on them, they will reveal the true URL of the page at that point. If that matters, then this method will not work.


I don't like this method, but maybe you could use a full-window IFRAME to hold the appropriate page - catalog.aspx would be nothing but a big frame, and you could set the source of that frame in your codebehind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜