को संभालने में नहीं है प्रश्न: कस्टम त्रुटि हैंडलिंग मौजूदा गैर-मौजूदा पथ/निर्देशिकाओं के लिए क्यों काम नहीं कर रही है?कस्टम त्रुटि वेब.कॉन्फिग/ग्लोबल.एएसएक्स में हैंडलिंग गैर-मौजूद निर्देशिका
निश्चित कोड के साथ अपडेट किया (आप के लिए हर किसी के लिए धन्यवाद इनपुट):
* web.config के लिए कोड अपडेट किया गया और Global.asax *
<httpErrors errorMode="Custom">
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/*****.aspx" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="-1" prefixLanguageFilePath="" path="/*****.aspx" responseMode="ExecuteURL"/>
</httpErrors>
added this to the global.asax to stop IIS from handling my 500 errors
after @Kev's suggestions IIS handled my 500's these lines fixed that
HttpApplication myApplication = new HttpApplication();
myApplication.Response.TrySkipIisCustomErrors = true;
हम एक साइट है web.config
और global.asax
में कस्टम त्रुटि हैंडलिंग के साथ सेटअप (सेटअप नीचे दिखाया गया है)। हम सभी 404 और 500 के बिना किसी समस्या के हैंडल करने में सक्षम हैं। त्रुटियों को Application_Error
में global.asax
में पकड़ा गया है, डीबी में लॉग इन किया गया है और फिर HttpContext
का उपयोग करके हम स्थिति कोड सेट करते हैं और उपयोगकर्ता को उचित त्रुटि पृष्ठ पर ले जाने के लिए Server.Transfer()
का उपयोग करते हैं (रीडायरेक्ट 302 का कारण बनता है, और एसईओ को नुकसान पहुंचाता है)।
समस्या तब होती है जब उपयोगकर्ता http://www.example.com/whatever
में टाइप करता है एक खाली पृष्ठ फ़ायरफ़ॉक्स में दिखाया गया है और आईई में यह आईई 404 पेज दिखाता है। फायरबग दिखाता है कि कोई स्टेटस कोड निकाल दिया जा रहा है, और जब मैं समाधान डीबग करता हूं, तो मैंने सेट किए गए ब्रेकपॉइंट्स को global.asax
में हिट नहीं किया जाता है। अजीब चीज यह है कि कोई उपयोगकर्ता http://www.example.com/whatever/hmm.aspx
दर्ज कर सकता है और एक त्रुटि मारा जाएगा। ऐसा लगता है कि यह केवल गैर-मौजूदा पृष्ठों पर काम कर रहा है, न कि पथ/निर्देशिका जो मौजूद नहीं हैं।
त्रुटियों के लिए मेरा web.config
कोड और आवेदन त्रुटि के लिए मेरे global.asax
कोड नीचे है।
मैं जोड़ दिया है * * जानकारी को छिपाने के लिए, वे उन्हें में मान्य .aspx
पृष्ठों है:
वेब config:
<customErrors defaultRedirect="~/******.aspx" mode="On"
redirectMode="ResponseRewrite">
<error statusCode="500" redirect="~/*****.aspx" />
<error statusCode="404" redirect="~/*****.aspx" />
</customErrors>
<httpErrors errorMode="Custom">
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/*****.aspx" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="-1" prefixLanguageFilePath="" path="/*****.aspx" responseMode="ExecuteURL"/>
</httpErrors>
कोड:
protected void Application_Error(Object sender, EventArgs e)
{
// At this point we have information about the error
HttpContext ctx = HttpContext.Current;
// set the exception to the Context
Exception exception = ctx.Server.GetLastError();
// get the status code of the Error
int httpCode = ((HttpException)exception).GetHttpCode();
// get the IP Address
String strHostName = string.Empty;
String ipAddress_s = string.Empty;
strHostName = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostByName(strHostName);
System.Net.IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
ipAddress_s += "IP Address {" + (i + 1) + "} " +
addr[i].ToString() + Environment.NewLine;
}
// setup the error info one for user display and one for the DB Insert
string errorInfo =
"<br /><b>Error Location:</b> " + ctx.Request.Url.ToString() +
"<br /><br /><b>Error Source:</b> " + exception.Source +
"<br /><br /><b>Error Try/Catch:</b> " + exception.InnerException +
"<br /><br /><b>Error Info:</b> " + exception.Message +
"<br /><br /><b>Status Code:</b> " + httpCode +
"<br /><br /><b>Stack trace:</b> " + exception.StackTrace;
string errorInfoDB =
"||Error Location: " + ctx.Request.Url.ToString() +
"||Error Source: " + exception.Source +
"||Error Try/Catch: " + exception.InnerException +
"||Error Info: " + exception.Message +
"||HttpErrorCode: " + httpCode +
"||Stack trace: " + exception.StackTrace +
"||IP Address: " + ipAddress_s;
// clean the input befor you put it in the DB
char quote = (char)34;
char filler = (char)124;
char tick = (char)39;
char greaterThan = (char)60;
char lessThan = (char)62;
errorInfo = errorInfo.Replace(quote, filler);
errorInfo = errorInfo.Replace(tick, filler);
errorInfo = errorInfo.Replace(greaterThan, filler);
errorInfo = errorInfo.Replace(lessThan, filler);
errorInfoDB = errorInfoDB.Replace(quote, filler);
errorInfoDB = errorInfoDB.Replace(tick, filler);
errorInfoDB = errorInfoDB.Replace(greaterThan, filler);
errorInfoDB = errorInfoDB.Replace(lessThan, filler);
string pattern = string.Empty;
string replacement = "sQueEl";
pattern = "/cookie|SELECT|UPDATE|INSERT|INTO|DELETE|FROM|NOT IN|WHERE|TABLE|DROP|script*/ig";
errorInfoDB = Regex.Replace(errorInfoDB, pattern, replacement);
pattern = "/cookie|select|update|insert|into|delete|from|not in|where|table|drop|script*/ig";
errorInfoDB = Regex.Replace(errorInfoDB, pattern, replacement);
if (httpCode == 404)
{
InSert_To_DB_Class(*****, *****, *****, *****, *****, errorInfoDB);
}
else
{
InSert_To_DB_Class(*****, *****, *****, *****, *****, errorInfoDB);
}
// set the error info to the session variable to display to the allowed users
Application["AppError"] = errorInfo;
// clear the error now that is has been stored to a session
ctx.Server.ClearError();
ctx.Response.ClearHeaders();
// set the status code so we can return it for SEO
ctx.Response.StatusCode = httpCode;
ctx.Response.TrySkipIisCustomErrors = true;
HttpApplication myApplication = new HttpApplication();
myApplication.Response.TrySkipIisCustomErrors = true;
try
{
if (ctx.Request.RawUrl.Contains("/*****"))
{
// redirect to the error page
ctx.Server.Transfer("~/*****.aspx", false);
}
else if(ctx.Request.RawUrl.Contains("/*****"))
{
ctx.Server.Transfer("~/*****/*****.aspx", false);
}
else
{
// check the httpCode
if (httpCode == 404)
{
// set the page name they were trying to find to a session variable
// this will be cleared in the ****** page
Application["404_page"] = exception.Message;
// redirect to the 404 page
ctx.Server.Transfer("~/*****", false);
}
else
{
// redirect to the error page
ctx.Server.Transfer("~/*****", false);
}
}
}
}
आपका कॉन्फ़िगरेशन नमूना अमान्य है - कृपया संवेदनशील डेटा को घटाकर _actual_ स्निपेट पोस्ट करें। –