2011-07-02 17 views
1

は次の通りであるとしてサブドメインを書き換え、私は、URLのこの種を書き換えたい:Asp.net 4 URLフォルダ私は何をしようとしている

domain.com/blog/... 

blog.domain.com/... 

にです共有ホスト環境では、IIS7/ASP.Net 4を使用します。もう1つの点は、ドメインとブログの両方のサブドメインが異なるAPを実行していることです。私はここで最善の解決策が何時間あるかを探してきました。私はここで少し私を導くことができれば幸いです。ありがとう!

答えて

0

ここでは、最初の考えとしての試みです。

// keep a valid list somewhere 
    List<string> cValidNames = new List<string>(); 
    cValidNames.Add("blog"); 

    // get the host 
    //string TheHost = Request.Url.Host; 
    string TheHost = "blog.domain.com"; 

    // find the first part, assume that the domain is standard and not change 
    int WhereStarts = TheHost.IndexOf(".domain.com"); 

    // if we found it 
    if(WhereStarts != -1) 
    { 
     string cTheFirstPart = TheHost.Substring(0, WhereStarts); 

     // if its on the valid domain (exclude the www) 
     if (cValidNames.Contains(cTheFirstPart)) 
     { 
      // now I add in the frond the name and continue with the rest url 
      string cFinalPath = "/" + cTheFirstPart + Request.RawUrl; 

      // now rewrite it. 
      HttpContext.Current.RewritePath(cFinalPath, false); 

      return; 
     } 
    } 
関連する問題