473,804 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Context.Rewrite path following Querystring access

Some time ago I posted a request for help with a problem I was having
sometime ago whereby a 404 error would result if any access to the
Querystring had been made before the Context.Rewrite path is called.
(http://groups.google.co.uk/groups?hl...&threadm=66a19
d98.0212240627. 3f123293%40post ing.google.com)

I have recently received a number of emails from people asking if I ever
found a solution, so I thought I'd post what I have done to work around this
problem. I am not saying this is the right solution but it works, and it
solved a huge headache for me.

private System.Collecti ons.Hashtable LocalQuerystrin g;

public void Application_Beg inRequest(objec t sender, EventArgs e) {
//cast sender into instance of HttpApplication class
HttpApplication application = (HttpApplicatio n)sender;

// retrieve requested Url
string requestedUrl = application.Req uest.Url.ToStri ng();

// get all querystring data
int qsPos = requestedUrl.In dexOf("?");

// Again not sure if this is the best way of doing this
if(qsPos > -1) {
qs = requestedUrl.Su bstring(qsPos+1 );
} else {
qs = "";
}
LocalQuerystrin g = LoadQueryString (qs);

// You can now access any querystring variable using the following
syntax
// LocalQuerystrin g["version"}.ToSt ring()
// This would return the value of the version querystring parameter,
without having to use
// the Request.Queryst ring object, the below rewritepath should now work
as planned!
// now do required rewritePath redirect
Context.Rewrite Path("template. aspx?pagename=" +
application.Ser ver.UrlEncode(R equest.Path));
}

// Loads all of the parameters passed in the querystring into Hashtable and
returns this Hashtable
private System.Collecti ons.Hashtable LoadQueryString (string qs) {
System.Collecti ons.Hashtable qsHash = new
System.Collecti ons.Hashtable() ;
string[] qsArr = qs.Split("&".To CharArray());

foreach(string s in qsArr) {
string[] item = s.Split("=".ToC harArray());
try {
qsHash.Add(item[0].ToString(), item[1].ToString());
} catch(System.Ex ception ex) {}
}
return qsHash;
}

Hope the above helps someone out.

On a similar note, one of the other issues we have experienced with this
methodology is that when the page is served the form action uses the the
rewritten path, not the requested url. This means that viewstate data
cannot be loaded and causes an error. To overcome this we output a
javascript function with every page that overwrites the action attribute of
the form with the correct value, i.e. the originally requested path. This
enable the viewstate to be loaded correctly.

Has anyone else out there found a better solution for the above problem? I
hate having to use Javascript to perform this task as it is far less
reliable than actually having the correct action output with the page. Is
there a way to override the rendering of the webform action attribute?

Any help appreciated.

Thanks,

Matt Howeson
http://www.3internet.com
Please take a look at our Inigo Content Management System on our website.
C#, Asp.net driven wysiwyg content management.
Nov 18 '05 #1
0 2268

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2662
by: Ayende Rahien | last post by:
I've a very annoying problem, I'm using Application_BeginRequest() and Context.RewritePath to hide query strings. The problem that I've is that a form that I submit to /Comments/17.aspx has form action of CommentView.aspx?story=17 (which is where the Context.RewritePath sent it). The problem that I'm having is that the end result is that the form end up being submitted to /Comments/CommentView.aspx?story=17, which doesn't even exist....
0
1516
by: Ayende Rahien | last post by:
I've a very annoying problem, I'm using Application_BeginRequest() and Context.RewritePath to hide query strings. The problem that I've is that a form that I submit to /Comments/17.aspx has form action of CommentView.aspx?story=17 (which is where the Context.RewritePath sent it). The problem that I'm having is that the end result is that the form end up being submitted to /Comments/CommentView.aspx?story=17, which doesn't even exist. How...
8
1869
by: Jiho Han | last post by:
Can someone explain in layman's term, what HttpContext.RewritePath does? SDK doc explanation is kind of scant. Does it only affect the request processing for the duration of the processing(meaning server side), or is the client in anyway affected? Thanks
1
3120
by: Oytun YILMAZ | last post by:
Hi I thing I have found a critical bug about ASP.NET ReWritePath Function Here are the steps to reproduce: I have a solution with this items: "MasterPageWithoutUserControl.aspx" "MasterPageWithUserControl.aspx" "OrdinaryPage.aspx"
15
6746
by: James Higgs | last post by:
For a long time, our product has had a "vanity URLs" feature where nice URLs are mapped to ASPX files in an IHttpModule implementation, using HttpContext.RewritePath(). This has worked beautifully for the past couple of years under .NET 1.1, but when it runs under ASP.NET 2.0 it has problems. Note that this is the case regardless of whether the assmbly is built against 1.1 or 2.0 We're getting the following exception stack trace: ...
1
2455
by: Alan Silver | last post by:
Hello, I have a page where site owners can see orders placed on their site. The path to this page is /dap/order.aspx, but for security reasons (as they will end up printing these pages and sending them to customers) I am trying to rewrite the path so the URL shown in the page footer is not a real one. I want to use an URL like http://www.domain.com/order123.aspx and have it rewritten to http://www.domain.com/dap/order.aspx?orderid=123
0
1413
by: Andrew2 | last post by:
Sorry guy for the (probably) stupid question, but reading and testing the second overload of the Context.RewritePath, that one with the rebaseClientPath param. Msdn says: true to reset the virtual path; false to keep the virtual path unchanged. I'd tried to use both combination and I'm not able to see any changes in the address bar, in Context.Request.RawUrl nor Context.Request.Path.
1
3484
by: Keef | last post by:
Hiya... just wondering if anyone else has come across this problem, and if there is a solution... i'm writing a reasonably simple IHttpModule to rewrite URLs ... in the BeginRequest event i do a app.Context.RewritePath("~/"+theFile,false) to the aspx file to display the content, then in the PreRequestHandlerExecute i do another RewritePath so that all the relative
4
11957
by: AAaron123 | last post by:
trying to understand the below shown code. After this is run the browser opens a file-save dialog box for saving the file. I wonder how it knows I want the file saved? But more important, the dialog box has as the default file name the name of this ashx file. I'd like to make that name more meaningfull but don't know how it gets set. I'm looking for a Response.Write but don't find one. Maybe that why the
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.