Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 532987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:27:44+00:00 2026-05-13T09:27:44+00:00

I’m trying to develop my first site in ASP.Net using Web Forms. I have

  • 0

I’m trying to develop my first site in ASP.Net using Web Forms.

I have a form with some controls and a TextBox control. While now I use GETrequest. When user submits a form his browser expects to get long URL, something like

http://mysite.com/search.aspx?__VIEWSTATE=%2FwEPDwUJNTE2NjY5jMY4D2QWAgICD2QWAgIDDW8wAh4EVGV4dAUBMWRkZKthQ0zeIP5by49qIHwSuW6nOj8iLTdoCUzpH369xyg8&__EVENTVALIDATION=%2FwEWAwLnrcHhBQLs0bLrBgKM54rGBjGtX5fJOylLy4qRbt6DqPxO%2FnfcMOkHJBRFqZTZdsBD&TextBox1=sfs&Button1=Button

if his input is a word sfs in TextBox1.
So I need to return him response. I would like to show this response on a user-friendly URL like

http://mysite.com/search.aspx?TextBox1=sfs

or
http://mysite.com/sfs

or
http://mysite.com/search/sfs

How can I do that? If I use Response.Redirect, it first returns 302, and only then work on short URL. Server.Transfer doesn’t change URL and user sees ugly long URL in browser.

It seems to me that it is possible to solve via RouteCollection.MapPageRoute which appeared in 4.0 Framework but it’s unclear to me how I can use it.

Any help is appreciated.

UPDATE. It is not a problem to use POST instead of GET. But in this way URL will always look like http://mysite.com/search.aspx

UPDATE2. The form MUST be server control and it has another controls except submit and textbox. It would be good (though, still, not necessary if this parameters don’t appear in URL showing in the browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:27:44+00:00Added an answer on May 13, 2026 at 9:27 am

    Since its a GET request you can also use javascript, setting the

    location.href = 'http://mysite.com/search/' + query; 
    

    Then on the ASP.NET side you can use the URL Rewriting feature to redirect that url to a specific ASPX page as a query string parameter.

    Let me know if you would like a more detailed sample.

    Sample:

    Here is a sample, please note I haven’t tested it, but this should get you started.

    <html>
    <head>
      <script type="text/javascript">
        function searchRedirect()
        {
          var query = $get('query');
          location.href = "/search/" + query.value;
        }
      </script>
    </head>
    <body>
        <div class="search">
            <input type="text" id="query" /><br />
            <input type="button" id="search" value="Search" onclick="searchRedirect();" />
        </div>
    </body>
    </html>
    

    Then on the redirect side you have have a RouteModule like this:

    public class UrlRewriter : IHttpModule
    {
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication context)
        {
            context.AuthorizeRequest += new EventHandler(OnBeginRequest); //this ensures the login page has the vitual url not the mapped url
        }
    
    
        private void OnBeginRequest(object sender, EventArgs e)
        {
            var application = sender as HttpApplication;
            if (application != null)
            {
                var requestPath = application.Request.AppRelativeCurrentExecutionFilePath;
                if (requestPath.ToLower().StartsWith("/search/"))
                {
                    var query = requestPath.Substring(8);
                    application.Context.RewritePath("Search.aspx", null, "query=" + query, false);
                }
                // .. Other Routes
            }
        }
    }
    

    And assuming the code is in your App_Code folder you could use this in your web.config

    <system.web>
      <!-- ... -->
      <httpModules>
          <add name="UrlRewriter" type="UrlRewriter, __code"/>
      </httpModules>
    </system.web>
    
    <!-- If IIS7 -->
    <system.webServer>
      <modules>
        <add name="UrlRewriter" type="UrlRewriter, __code" />
      </modules>
    </system.webServer>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 387k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This filter checks if any of the words in the… May 15, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer maybe this? echo $_SERVER['HTTP_REFERER']; May 15, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer Use an NSTimer so the run loop has time to… May 15, 2026 at 12:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.