Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

kinda complicated redirect question

Status
Not open for further replies.

ahevans

Technical User
Jan 27, 2006
26
GB
Hi all

I'm seriously struggling with finding a solution for the following problem in asp .net.

I have an IIS server which hosts one site but IIS uses host headers to accept two different URLs. The site is in ASP .Net and is a dynamic site that runs off default.aspx in the root (no subdirectories or other files). One url is and the other (note the nww as it's an intranet site).

What I want to do is if it is if a user requests change this to (SSL) without affecting the GET variables which may come after the doument in the request e.g. should become
Anyone have an idea how I can achieve this?

Thanks
 
If all you want to do is to force a redirect to an https site is to include the following code:

Code:
protected void Page_Load(Object sender, EventArgs e)
{
    if (Request.ServerVariables["SERVER_PORT"] == "80")
    {
        string strSecureURL;
        strSecureURL = "[URL unfurl="true"]https://";[/URL]
        strSecureURL = strSecureURL + Request.ServerVariables["SERVER_NAME"];
        strSecureURL = strSecureURL + Request.ServerVariables["URL"];
        Response.Redirect(strSecureURL);
    }
}

If you are using ASP.NET 2.0, you can include this code in the code behind file of the master page of the site. Otherwise, you'll have to figure out a way to include the code in every page in the site that you want to force SSL.
 
>>Otherwise, you'll have to figure out a way to include the code in every page in the site that you want to force SSL.

thats what HttpModules will do...

Known is handfull, Unknown is worldfull
 
Will this work?

<%
if Request.ServerVariables("SERVER_NAME") = "nww.domain.com" then
Redirect_URL = " & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING")

Response.Redirect(Redirect_URL)
end if
%>
 
It should do but vbkris has pointed out probably the best method to implement the redirect.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top