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

  • SEARCH
  • Home
  • 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 822123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:45:13+00:00 2026-05-15T02:45:13+00:00

What is the simplest way to redirect a web request to an ASP.NET application

  • 0

What is the simplest way to redirect a web request to an ASP.NET application to a subdomain?

If a request comes into the URL http://somesite.com/foo.aspx, the new destination URL should be

  • http://www.somesite.com/foo.aspx or
  • http://blog.somesite.com/foo.aspx

How can you programmatically redirect the request to the subdomain, keeping the rest of the URL intact?

  • 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-15T02:45:14+00:00Added an answer on May 15, 2026 at 2:45 am

    You could try something like this
    A simple method that you can hook up to the Global.asax

    Here’s my Class

    Imports System.Web.UI.HtmlControls        
    Imports System.Web.UI        
    Imports System.Web   
    
    Public Class HelperPage  
        Inherits System.Web.UI.Page  
    
        ''# Force WWW     
        Public Shared Sub ForceWWW()  
            If Not GetServerDomain.StartsWith("www.") Then 
                HttpContext.Current.Response.Status = "301 Moved Permanently" 
                HttpContext.Current.Response.AddHeader("Location", "http://www." & GetServerDomain() & HttpContext.Current.Request.RawUrl)  
            End If 
        End Sub 
    
        Public Shared Function GetServerDomain() As String 
            Dim myURL As String = HttpContext.Current.Request.Url.ToString  
            Dim re As New Regex("^(?:(?:https?\:)?(?:\/\/)?)?([^\/]+)")  
            Dim m As Match = re.Match(myURL)  
            Return m.Groups(1).Value  
        End Function    
    End Class 
    

    and here’s my call in the Global.asax

    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)  
                HelperPage.ForceWWW()  
    End Sub 
    

    With that bit of code.. you will always be forced over to the WWW version of your website (providing that the Host Header in IIS has both the www and the non www version listed.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the simplest and most effective way to selectively redirect HTTP requests to your
The simplest way to transform an in-proc COM server into an out-proc COM server
What's the simplest way to convert a Unicode codepoint into a UTF-8 byte sequence
My goal is to have the url routing as following: http://www.abc.com/this-is-peter-page http://www.abc.com/this-is-john-page What is
What is the simplest way to create a HTTP proxy with Python? As far
What would be the simplest way to convert an existing application with xib files
What is the simplest way of converting my .NET C# windows forms app to
The simplest way to launch a web browser from within a blackberry app is:
What is the simplest way to split arrays into multiple arrays based on some
What's the simplest way to connect and query a database for a set of

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.