2017-12-13 14 views
0

Global.asax 파일 및 App_global.asax.compiled 또한 App_global.asax.dll이 포함 된 웹 사이트를 실행하고 있지만 이제는 URL 재 작성의 기존 코드를 편집하거나 추가하려고합니다. 하지만 global.asax 파일에서 코드를 수행 할 때 수행하지 않습니다.Global.asax 파일을 편집하여 웹 사이트에 구현하십시오.

Google 검색 및 검색 결과가 많은 경우 변경을 완료 한 후에 해당 글로벌 파일을 다시 컴파일해야한다는 것을 알게되었습니다. 하지만 나는 Websi ## Heading ## 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>