, Archive for Juli 2016

Menggunakan web.config 404 Untuk Pesan Error http kustom pada IIS 7.5

File web.confiq memungkinkan Anda untuk membuat halaman error http kustom untuk situs web Anda. Kesalahan kustom dapat diatur arau 
diganti secara luas  direktori by direktori pafa situs Sementara beberapa bagian web.confiq mengharuskan direktori diatur sebagai aplikasi, ini bukan salah satu dari mereka. Sebuah web.cinfiq yang sederhana dengan bagian httpErrors dapat ditempatkan dalam direktori apapun, dan direktori TIDAK perlu ditetapkan sebagai aplikasi. 

Apa Kesalahan HTTP?
Error HTTP dikembalikan kepada klien ketika sesuatu berjalan salah pada server. Kesalahan kode status dikembalikan jika file  yang diminta tidak ditemukan (404), halaman web (500), dan karena masalah sementara seperti koneksi database gagal (500). Kesalahan yang paling umum adalah 404(file tidak ditemukan) dan 500 (kesalaha aplikasi) dan 500 (aplikasi). 

404 dan 500 kesalahan biasanya digunakan untuk memberikan pesan ramah kepada pemhguna Anda. 

404 dan 500 kesalahan juga bisa mengarahkan pengguna ke default  (atau) halaman, dan kadang-kadang digunakan untuk memberitahu administrator situs web dari masalah pada situs web. Jika Anda ingin mengkonfigurasi  kesalahan kustom untuk situs Anda, silahkan ikuti petunjuk pada halaman ini. 
400 Kesalahan ( permintaan buruk) 
401 Kesalahan (tidak sah)
403 Kesalahan (dilarang)
404 Kesalahan (tidak ditemukan)
500 Kesalahan (server error internal)   

Bagaimana itu bekerja?
Contih kustom http error. Komen-komen berada dalam <!-- --> dan tidak dibutuhkan.


required.
  • Capture and return specific error types
    <httpErrors>
           <remove statusCode="401" subStatusCode="-1" />
           <remove statusCode="403" subStatusCode="-1" />      
           <remove statusCode="404" subStatusCode="-1" />                
           <remove statusCode="500" subStatusCode="-1" />
              <!-- full url when responsemode is Redirect -->
           <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
              <!-- local relative path when responsemode is ExecuteURL -->
           <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
           <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />                
           <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
    </httpErrors>
    

Using Custom Errors
  • Use a text editor to create a file named web.config
  • Save the web.config file with the appropriate content
  • Place the web.config file in the directory that you wish to modify

Detailed web.config content
  • If there isn't an existing web.config in the directory, your new web.config should look something like this
    <?xml version="1.0"?>
    <configuration>
       <system.webServer>
          <httpErrors>
            <remove statusCode="401" subStatusCode="-1" />
            <remove statusCode="403" subStatusCode="-1" />      
            <remove statusCode="404" subStatusCode="-1" />                
            <remove statusCode="500" subStatusCode="-1" />
              <!-- full url when responsemode is Redirect -->
            <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
              <!-- local relative path when responsemode is ExecuteURL -->
            <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
            <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />                
            <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
          </httpErrors>
          <modules runAllManagedModulesForAllRequests="true"/>
       </system.webServer>
    </configuration>
    
  • Jika ada sebuah web.confiq tanpa suatu seksi webSeIf there is an existing web config, without a <system.webServer> section... Your new web.config should look like this
    <?xml version="1.0"?>
    <configuration>
       <system.web>
         .. existing text ..
         .. existing text ..
       </system.web>
       <system.webServer>
          <httpErrors>
            <remove statusCode="401" subStatusCode="-1" />
            <remove statusCode="403" subStatusCode="-1" />      
            <remove statusCode="404" subStatusCode="-1" />                
            <remove statusCode="500" subStatusCode="-1" />
              <!-- full url when responsemode is Redirect -->
            <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
              <!-- local relative path when responsemode is ExecuteURL -->
            <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
            <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />                
            <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
          </httpErrors>
          <modules runAllManagedModulesForAllRequests="true"/>
       </system.webServer>
    </configuration>
    
  • Jika ada web.confiq Anda  yang sudah mempunyai sebuah seksi <system web>, tinggal tambahkan ini: 
    <?xml version="1.0"?>
    <configuration>
       <system.web>
         .. existing text ..
         .. existing text ..
       </system.web>
       <system.webServer>
          <httpErrors>
            <remove statusCode="401" subStatusCode="-1" />
            <remove statusCode="403" subStatusCode="-1" />      
            <remove statusCode="404" subStatusCode="-1" />                
            <remove statusCode="500" subStatusCode="-1" />
              <!-- full url when responsemode is Redirect -->
            <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
              <!-- local relative path when responsemode is ExecuteURL -->
            <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
            <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />                
            <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
          </httpErrors>
          <modules runAllManagedModulesForAllRequests="true"/>
       </system.webServer>
    </configuration>
    


0 komentar:

Untuk Melanjutkan Membaca Silahkan Lengkapi Form Ini