Click here to Skip to main content
15,885,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to do Page redirection of 303 status code in asp.. When I provide the tempURL(manually generated) in browser the link has to be automatically redirected to the original URL.. I will be having DB for each tempURLs and corresponding original URL.. I need the dynamic page redirection.. Please don't provide solution for static redirects using web.config file..

if I have my webconfig as
HTML
<rewriter>
     <rewrite url="http://www.mycompany.in/" to=originalUrlMatchedFromDBForUSerRequest />
</rewriter>


How to change "originalUrlMatchedFromDBForUSerRequest" dynamically?
Posted
Updated 21-Mar-13 0:13am
v5

Add this in web.config:

XML
<customErrors mode="RemoteOnly" defaultRedirect="~/errorsfolder/ErrorPage.aspx" redirectMode="ResponseRewrite">
           <error statusCode="303" redirect="~/errorsfolder/yourerrorpage.aspx"/>
       </customErrors>
 
Share this answer
 
Comments
Janani Muthaiyan 21-Mar-13 3:26am    
The redirects will be dynamically changing for each tempURL's.. Then how the above is possible?
Try this
C#
Response.RedirectLocation = url;
 Response.StatusCode = 303;



For Ur Reference http://stackoverflow.com/questions/9497467/how-to-create-303-response-in-asp-net[^]
 
Share this answer
 
v2
Comments
Janani Muthaiyan 21-Mar-13 3:28am    
How it would recognize the request first? this is my doubt..
So you should go for Custom Errors in ASP.NET[^]
Try this:
HTML
<customerrors defaultredirect="~/SomeErrorPage.htm" mode="On">
   <error statuscode="303" redirect="~/YourPage.htm" />
</customerrors>

Also check Displaying a Custom Error Page (C#)[^].

[Edit]
Try this in your master page:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Response.StatusCode == 303)
    {
        switch (Request.Url.AbsoluteUri)
        {
            case "Your 1st LongURL":
                Response.Redirect("Your 1st SortURL");
                break;
            case "Your 2nd LongURL":
                Response.Redirect("Your 2nd SortURL");
                break;
            case "Your 3rd LongURL":
                Response.Redirect("Your 3rd SortURL");
                break;
            default:
                break;
        }
    }
}

[/Edit]

--Amit
 
Share this answer
 
v2
Comments
Janani Muthaiyan 21-Mar-13 3:31am    
@_Amy, Hi, This is my doubt.. When the requests the URL in browser world wide how it can be redirected from our code dynamically?
_Amy 21-Mar-13 3:34am    
When a runtime or design-time error occurs in an application, ASP.NET shows a default error page that gives a brief description of the error along with the line number on which the error occurred.ASP.NET provides several levels at which you can handle and respond to errors that may occur when you run an ASP.NET application.


--Amit
Janani Muthaiyan 21-Mar-13 3:38am    
No, no one understands my question.. Let me explain. I have 4 shortURLs for 4 longURLS respectively in DB. When I click the longurl world wide, it has to be redirected to it shorturl using 303 status code in c#. Even if I share my shorturl in fb, twitter,etc, anyone who clicks that links has to be redirected its original long url.
_Amy 21-Mar-13 4:15am    
Refer my updated solution. Put the codes in page load event of the master page.
Try below code

string url = Request.Url.ToString();

Get actual Url from Db.

Add status code to the response url.

Redirect user to the page.

And what have you tried so for??
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900