HandleError
एक विशेषता है।
संक्षिप्त परिचय के लिए गुण
गुण वर्ग कोष्ठक में दिए गए हैं, लगाकर कक्षाएं, structs, खेतों, मानकों, कार्य, और तर्क है, और आप एक कक्षा में गुण से इनहेरिट द्वारा स्वयं अपना निर्धारित कर सकते हैं। एक विशेषता बनाने के विशिष्ट स्वरूप है जैसे:
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct)]
public class NameOfYourAttributeAttribute : Attribute {
}
उदाहरण में ऊपर:
public class NameOfYourAttributeAttribute : Attribute {
}
तुम भी एक विशेषता है कि क्या यह करने के लिए आवेदन कर सकते हैं के दायरे को परिभाषित करता है के साथ अपने गुण परिभाषा उपसर्ग कर सकते हैं , कक्षा के लिए वास्तव में एक वर्ग या संरचना के लिए सजावट करने के अलावा, कक्षा के लिए इतना कुछ नहीं है।
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple = true)]
public class Author : System.Attribute
{
string name;
public double version;
public Author(string name)
{
this.name = name;
version = 1.0; // Default value
}
public string GetName()
{
return name;
}
}
[Author("H. Ackerman")]
private class FirstClass
{
// ...
}
// There's some more classes here, see the example link...
class TestAuthorAttribute
{
static void Main()
{
PrintAuthorInfo(typeof(FirstClass));
PrintAuthorInfo(typeof(SecondClass));
PrintAuthorInfo(typeof(ThirdClass));
}
private static void PrintAuthorInfo(System.Type t)
{
System.Console.WriteLine("Author information for {0}", t);
System.Attribute[] attrs = System.Attribute.GetCustomAttributes(t); // reflection
foreach (System.Attribute attr in attrs)
{
if (attr is Author)
{
Author a = (Author)attr;
System.Console.WriteLine(" {0}, version {1:f}", a.GetName(), a.version);
}
}
}
}
: MSDN, जहां कक्षाएं एक लेखक विशेषता दिया जा सकता है से एक उदाहरण (http://msdn.microsoft.com/en-us/library/z919e8tw%28v=vs.80%29.aspx) पर विचार करें
HandleError के मामले में, विशेष रूप से:
वे उपयोगी जानकारी प्रतिबिंब के माध्यम से देखा जा सकता है प्रदान करते हैं। HandleError
के मामले में, इसका अर्थ यह है कि यदि नियंत्रक के भीतर कोई अपवाद फेंक दिया जाता है, तो यह त्रुटि दृश्य को ~/Views/Shared/में प्रस्तुत करेगा।
अधिक जानकारी के लिए http://msdn.microsoft.com/en-us/library/system.web.mvc.handleerrorattribute.aspx देखें।
बहुत बढ़िया उत्तर। इससे बहुत मदद मिली। – Dan