Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Parameters using <httpRedirect> in ASP.Net

In my ASP.Net website I am permanently redirecting an URL to other location using <httpRedirect> in web config.
I am reading URL value from table and redirecting to that URL using Response.Redirect( URL );
It is working perfect.
But now when I try to send the parameter to the calling page using:

Response.Redirect("Default.aspx?name=stackoverflow");

<httpRedirect> in web.config calles the Default2.aspx because of following code in web.config:

<location path="Default.aspx">
    <system.webServer>
        <httpRedirect enabled="true" destination="Default2.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
</location>

The Problem is Default2.aspx does not receive any parameters.
Please help.

Note: I cannot use session variable as page contents depends on that parameter.

For instance,
If user opens another page in new tab with Default.aspx?name=MetaStackOverflow session variable will get replaced and if first page is refreshed then instead of showing Stackoverflow content it will show MetaStackOverflow.

like image 706
user1808827 Avatar asked Jan 22 '13 07:01

user1808827


People also ask

What is parameter binding in ASP NET Web API?

Parameter Binding in ASP.NET Web API. When Web API calls a method on a controller, it must set values for the parameters, a process called binding. This article describes how Web API binds parameters, and how you can customize the binding process.

How does the httpresponsemessage PUT () method work?

For example, here is a typical Web API controller method: HttpResponseMessage Put(int id, Product item) { ... } The id parameter is a "simple" type, so Web API tries to get the value from the request URI. The item parameter is a complex type, so Web API uses a media-type formatter to read the value from the request body.

How to pass multiple parameters to a GET method?

You have multiple options for passing multiple parameters to a GET method: FromRouteAttribute, FromQuery and Model Binding. In this article, we are going to learn how to pass multiple parameters to a GET method. This article covers the following points: What are the ways to pass multiple parameters to a GET method? What is Model Binding?

How do I get the value of a string in http?

The HTTP query string is specified by the values following the question mark (?). As you can see from the above query string example (just after “?”), we are passing the parameters in key:value pair, meaning that id is a key variable and txtId.Text is a value of that key.


1 Answers

Don't forget the special characters $V$Q and the exactDestination has to be set to True.

<location path="Help"> <system.webServer> <httpRedirect enabled="true" destination="/Redirect.aspx$V$Q" httpResponseStatus="Permanent" exactDestination="true" /> </system.webServer> </location>

like image 116
Lenard Bartha Avatar answered Oct 12 '22 11:10

Lenard Bartha