2017-12-13 5 views
0

Global.asaxファイルとApp_global.asax.comもApp_global.asax.dllを含むウェブサイトを運営していますが、現在はURLの書き換えの既存のコードを編集または追加したいと考えています。 しかし、global.asaxファイルでコードを実行すると、コードが実行されません。Global.asaxファイルを編集してウェブサイトに実装します

多くのグーグルと検索の後、私は変更が完了した後にそのグローバルファイルを再度コンパイルする必要があることを知りました。しかし、私はwebsiとしてそれを行うことはできません##見出し## teは生きていると私はそれのための解決策を持っていません。 Global.asaxの中

既存のコード:

protected void Application_BeginRequest(object sender, EventArgs e) 
    { 
     HttpContext myContext=HttpContext.Current; 

     Regex rewrite_regex = new Regex(@"(.+)\/((.+)\.*)", RegexOptions.IgnoreCase); 

     try 
     { 
       // 'see if we need to rewrite the URL 
      Match match_rewrite =rewrite_regex.Match(myContext.Request.Path.ToString()); 

      string str = match_rewrite.Groups[2].Captures[0].ToString(); 
      string root = match_rewrite.Groups[0].Captures[0].ToString(); 
      if (Regex.Match(root, "/News/", RegexOptions.IgnoreCase).Success) 
      {   
       myContext.RewritePath("~/Default2.aspx?nid="+str); 
      } 
      else if (Regex.Match(root, "/Search/", RegexOptions.IgnoreCase).Success) 
      { 
       myContext.RewritePath("~/Default.aspx?text=" + str); 
      } 
      else if (Regex.Match(root, "/Find/", RegexOptions.IgnoreCase).Success) 
      { 
       myContext.RewritePath("~/Default.aspx?text=" + str); 
      } 

すべてのヘルプはGREATFULになります。

答えて

0

コードをお持ちでない方が簡単な方法を使用します。IIS redirect rules? これにより、web.configにルールが追加されます。さまざまな条件を満たす複数の正規表現ベースのルールを作成できます。

<rule name="Redirect from blog"> 
     <match url="^blog/([_0-9a-z-]+)/([0-9]+)" /> 
     <action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" /> 
    </rule> 
関連する問題