Monday, 19 December 2016

MVC C# Error Handling

1. Object Can't be cast from Db null to other types.

Soln.--  Mostly comes when working with database, when we execute our query but after execution we didn't return anything and we are trying to achieve query result through functions. Suppose we have a procedure which is inserting our data to database and simultaneously getting return in some variables or parsing as parameter and our procedure that has only query to  insert not to return, in that case we are achieving null data in some datatype.
 To solve this only give a return type from your query after insert and  it will solve.


2. Dangerous Request Errors.

Soln--  This error comes when we are inserting some html content or executing html content to render in browser in .net.
 To Solve this we have to give validation mode configuration in httpRuntime as given below:

<httpRuntime targetFramework="4.5" requestValidationMode="2.0" />


3. Dangerous value Error  when working with Content Editors.

Soln--   Add  [Validate Input(false)] above action Result when working with mvc or add
            <httpRuntime targetFramework="4.5" requestValidationMode="2.0" /> in Web.config file.


4. Error with loading images in html

Soln--  Correct way of using path url in images are:
1. Use Absolute Url "~/foldername/filename
2. Use "../foldername/filename
3 Use Direct routing /foldername/filename

5. Not All code path returns a value

Soln--  Return type is not provided or not used at correct place.


6. </blockquote> Not supports in some editors in design mode.

Soln--  Save html without going into html mode.


7. 403 Status Code Error

Cause--  Removal of file permission or restriction of access permission, Accidental misconfiguration                of Web Server.


8. Dynamic and static routing problem:

Soln-- always use dynamic routing after all static routing. 

0 comments:

Post a Comment