2016-03-30 15 views
0

Eski web formları web sitesini ASP MVC web API'sine yeniden geliştirdim. Bazı eski URL'ler eski web formları URL ve sorgu dizesi ile arama motorları ve forumlarda görünür, ben sorgu dizesi kimliği ile arama ve değişken adı ile yeni siteye yönlendirmek için bunlara ihtiyacım var. Yönlendirmeyi gerçekleştirmek için kök MVC uygulamasına bir ASP web formu sayfası ekledim. Sorun, localhost'umdaki kodu denediğimde işe yarıyor ama sonra canlı web sitesinde denediğimde ana sayfaya yönlendiriyor. Bunun nedeni, http: https’e yeniden yönlendirmek için yeniden yazma kuralım olabilir. Emin değilim.http Web Form Sorgu Dizesini https olarak yeniden yönlendirin

akım bing url http://www.domain.com/View.aspx?ID=1

Bu işleri https://www.domain.com/View.aspx?ID=1 (https yerine http)

try 
{ 
    string url = "https://domain.com/NewPath/" + getNewName(Request.QueryString["id"]); 
    Response.Redirect(url, false); 
    HttpContext.Current.ApplicationInstance.CompleteRequest(); 
} 
catch (Exception) 
{ 
    Response.Redirect("https://domain.com"); 
} 

Web yapılandırma yeniden yazma kuralını şu şekilde

http://www.domain.com/NewPath/SampleName

Kod yönlendirmeler

<location path="app/views"> 
    <system.webServer> 
     <staticContent> 
     <clientCache cacheControlMode="DisableCache" /> 
     </staticContent> 
    </system.webServer> 
</location> 

<rewrite> 
     <rules> 
     <rule name="SecureRedirect" stopProcessing="true"> 
      <match url="^(.*)$" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="off" /> 
      <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" /> 
      </conditions> 
      <action type="Redirect" url="https://{C:2}" redirectType="Permanent" /> 
     </rule> 
     </rules> 
</rewrite> 

cevap

0

Bu URL http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

yardımcı

<?xml version="1.0" encoding="UTF-8"?> 
 
<configuration> 
 
    <system.webServer> 
 
     <rewrite> 
 
      <rules> 
 
       <rule name="Redirect to Https" stopProcessing="true"> 
 
        <match url="(.*)" /> 
 
        <conditions> 
 
         <add input="{HTTPS}" pattern="^OFF$" /> 
 
        </conditions> 
 
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> 
 
       </rule> 
 
      </rules> 
 
     </rewrite> 
 
    </system.webServer> 
 
</configuration>

IIS yeniden yazma kuralı

İlgili konular