Click here to Skip to main content
Click here to Skip to main content

Unlimited Query string - ASP.NET

By , 1 Sep 2010
 

Introduction

Query string is one of the primary parameter passing techniques for Web Application.

Query string has some limitation in terms of query string length; this length depends on the browser.

To handle the query string length limitation, there are few solutions –

  1. using POST instead of GET,
  2. passing by Cookies
  3. Sending query string to the server by AJAX and adding to the session in the first step and fetching the query string from the session using some GUID concepts.

Here I am going to explain a best and stable solution for all the cases.

Background

We have three situations when we need to pass query string to the web page.

  1. Opening a new window (http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx)
  2. Showing modal dialog (http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx)
  3. Showing the URL in iFrame (http://msdn.microsoft.com/en-us/library/ms537627(v=VS.85).aspx)

Request Maximum Size can be configured on IIS Server configuration for Server side.
http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits
[ Thanks : daveauld - http://www.codeproject.com/Members/daveauld  ]

Using the Code

To solve this problem, I have come up with a simple solution using HttpHandler & Javascript.

What is HttpHandler? Read this - http://aspalliance.com/441
How to create an HttpHandler? Read this - http://support.microsoft.com/kb/308001

This solution contains 2 parts, first one is launching/showing the URL using the WindowManager.Js script object, and second part for passing the query string to the web page from HttpHandler.

The below work flow diagram shows internally how it’s working.

How to Implement

Attached sample code contain 2 files, first one is the script file WindowManager.Js, Second one is HttpHandler source code – PageTransfer.CS.

Steps to integrate:

  1. Web.Config Changes.
    Add this entry under system.web\httpHandlers Node.
  2. <add verb="*" path="PageTransfer.axd" 
        type="ApplicationFrameWork.PageTransfer, ApplicationFrameWork"/>
    
         <!— type="ApplicationFrameWork.PageTransfer, AssemblyName"  -->
  3. Add these 2 files in your project folder.
  4. Include the script in your aspx page.
  5. <script src=" WindowManager.js" language="javascript"></script>

Let pass your unlimited query string to your pages.

<html>
<head>
<script src=" WindowManager.js" language="javascript"></script>
</head>
<script language="javascript">
      function OpeniFrame()
{
      WindowManager.LoadFrame("iFrameName", 'WebForm1.aspx', 
          'name=elayaraja&Your=UnlimitedQueryString', 'Your Title')
}

function OpenWindow()
{
      WindowManager.OpenWindow ('WebForm1.aspx', 'Your Title','400px','500px',
          'name=elayaraja&Your=UnlimitedQueryString')
}

function OpenModalWindow()
{
      WindowManager.OpenModalWindow('WebForm1.aspx', 'Your Title','400px','500px',
          'name=elayaraja&Your=UnlimitedQueryString')
}
 
</script>
<body>
    <form id="form1" runat="server">
    <div>
      Open Window <input type=button value="Open" onclick="OpenWindow()" />
      Load Frame Page<input type=button value="Frame" onclick="OpeniFrame()" />
      Open Modal Dialog<input type=button value="Frame" onclick=" OpenModalWindow()" />
 
    </div>

    <iframe id="iFrameName" width="100%" height="300px" frameborder=1>
    </iframe>

    </form>
</body>
</html>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Elayaraja Sambasivam
Architect iSOFT R&D Pvt Ltd
India India
Member
Currently working as Technical Architect at iSOFT R&D Pvt Ltd,Chennai.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questioniis limits toomemberderekchen10 Dec '12 - 16:55 
The Query string is limitted not only by web browsers(ie/ff/different ie versions),but only by iis(web server).
furyDC

GeneralinterestingmemberPranay Rana22 Dec '10 - 0:04 
going to try
For any question : http://pranayamr.blogspot.com/
 
vote my article :

Learn SQL to LINQ ( Visual Representation )


Calling WCF Services using jQuery

GeneralMy vote of 1memberOakman6 Sep '10 - 10:09 
Using the query string for much more than the transfer of a few values is a terrible idea. I am sure you meant to be helpful, but this article is about sticking 10 lbs of manure in a 5 lb bag.
GeneralNot bad, but...memberGregory.Gadow1 Sep '10 - 12:03 
If you are transferring that much data, passing it in the URL is probably not the best way to do it: there is a reason why browser- and server-imposed limits exist.
 
Rather than transferring the data in the query string, wrap it up and stuff it into the Session object. Session is not suitable for persisting data, but it is normally stable enough for the few seconds it takes to transfer from one page to another. This can be done very easily. On the page you are leaving:
    Dictionary < String, Object > Temp;
    Temp.Add("key1", value1);
    Temp.Add("key2", value2);
 
    Session["PageData"] = Temp;
    Response.Redirect("NewPage.aspx");
And then on the page you are going to:
    Dictionary<String, Object> Temp;
    Temp = Session["PageData"];
    Session.Remove("PageData");
 
Simple, efficient, and much more flexible than the query string, in that you can pass actual objects rather than just string data.
GeneralRe: Not bad, but...membersambasivam elayaraja1 Sep '10 - 20:00 
Hi,
 
Using session for this kind of approch may be right decision for small projects.
But for enterprise applications, we should avoid the session based solutions.
If the session is managed in the database it will not scale because session will be retreived/rewritten during each postback of any aspx pages in the web application.
GeneralRe: Not bad, but...memberGregory.Gadow2 Sep '10 - 3:22 
If your code does not reference the Session object, then it is not referenced. If you must transfer a massive amount of data from one page to another and such transfers are reasonably rare, then Session should be fine even if you are using a SQL-based session model. I would think trying to use the URL to transfer the data would be far less scalable.
GeneralRe: Not bad, but...memberOakman6 Sep '10 - 10:03 
Gregory.Gadow wrote:
I would think trying to use the URL to transfer the data would be far less scalable.

 
You couldn't be more right. The concept of transferring a great deal of data via the query string simply boggles the mind.
The practical reason for freedom is that freedom seems to be the only condition under which any kind of substantial moral fiber can be developed — we have tried law, compulsion and authoritarianism of various kinds, and the result is nothing to be proud of. ~ Albert Jay Nock

GeneralBad ProgrammingmemberCorey Fournier1 Sep '10 - 8:21 
I don't know what situation warrants this, but to me this just screams bad programming.
GeneralRe: Bad ProgrammingmemberMunim Abdul1 Sep '10 - 9:34 
I agree with you! Very immature and unprofessional. Would suit for 1st year college student.
QuestionRe: Bad Programmingmembersambasivam elayaraja1 Sep '10 - 20:14 
Hi,
 
While writing enterprise application in web, it is not possible to keep all the parameters(related to the current user/screen) in the Database as well in the session. Without moving them to the client machine, it will not scale more than 3000 users.
 
I have the same comment on your statement - immature and unprofessional. I would have felt little happy if you had substantiated your comment with a backup solution. It seems like there is no experience of working in an enterprise application and your comment looks like a comment from first year college student !
QuestionRe: Bad Programmingmembersambasivam elayaraja1 Sep '10 - 20:15 
Hi,
 
While writing enterprise application in web, it is not possible to keep all the parameters(related to the current user/screen) in the Database as well in the session. Without moving them to the client machine, it will not scale more than 3000 users.
AnswerRe: Bad ProgrammingmemberEric Xue (brokensnow)3 Sep '10 - 23:25 
There are a few questions with regards to why it needs extremely long parameter string in the query string for this particular in the first place.
 
1. If the application itself couldn't take Session variables to pass around the parameters between pages (in the asp.net application), the application should construct the strong-typed object to narrow down the number of parameters, then only pass 'id's around across different pages unless there is a tracker involved (Google, Yahoo and etc). By doing that, it wouldn't require a tedious super long query string on the client-side.
 
2. Why not using Cookies? It can make the extremely long go away, can't it?
 
3. Lastly, why not use Http "POST"? By doing that, the parameters could be input fields available within the .net Request Object rather than the lengthy query string parameters. This approach also works well in asp.net AJAX as well, right?
 
Let me know where your thoughts are on those questions and look forward to your further response.
 
All Best
E
Generalplease format the articlemember ThatsAlok 31 Aug '10 - 18:33 
It would be good, if you submit it using article submission by email rather than directly posting on site.
 
There are chances author review your article and format it for good!

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixture

cheers,
Alok Gupta
VC Forum Q&A :- I/IV
Support CRY- Child Relief and You

GeneralLength Limitationsmemberdaveauld31 Aug '10 - 7:43 
In your article you state that the length is limited by the browser. This is true, but it may also be of value to make the statement that the server may also impose limitations on the length of QueryStrings and total length of the URL for instance, see this page on IIS configuration;
 
http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits[^]
 
I think it is also fair to say that if someone is wanting to make really long query string requests, they ain't going to be doing this with a browser, it is going to be called from a custom app.
 
So, i think the server imposed limitation is more an important statement than the browser imposed limitation.
Dave
 
Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 1 Sep 2010
Article Copyright 2010 by Elayaraja Sambasivam
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid