Click here to Skip to main content
15,888,454 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: I want to show data in gridview even if only one dropdown is selected..what will be the store procedure Pin
User 418025425-Apr-17 2:43
User 418025425-Apr-17 2:43 
GeneralRe: I want to show data in gridview even if only one dropdown is selected..what will be the store procedure Pin
Member 1314815825-Apr-17 19:48
Member 1314815825-Apr-17 19:48 
GeneralRe: I want to show data in gridview even if only one dropdown is selected..what will be the store procedure Pin
User 418025426-Apr-17 4:18
User 418025426-Apr-17 4:18 
QuestionIE 11 giving XML5619: Incorrect document syntax Pin
dpkcp24-Apr-17 0:03
dpkcp24-Apr-17 0:03 
AnswerRe: IE 11 giving XML5619: Incorrect document syntax Pin
User 418025424-Apr-17 3:08
User 418025424-Apr-17 3:08 
QuestionDecide flow/featurs of ASP.NET MVC Project Pin
Member 1266445222-Apr-17 0:57
Member 1266445222-Apr-17 0:57 
AnswerRe: Decide flow/featurs of ASP.NET MVC Project Pin
User 418025422-Apr-17 4:18
User 418025422-Apr-17 4:18 
QuestionError Page , 404, 500 Pin
jkirkerx20-Apr-17 11:00
professionaljkirkerx20-Apr-17 11:00 
I thought I had this worked out in my main project, then I created a lite version of the project.
I can't figure out how to get my error handler page to work.

What works
Exception Pages when a page fails, I get the Exception message.

What doesn't work
when I have the URL up say Home, and I type in /Home/jllk;lk;lk;l junk, I expect to get the /Error/Page404 or /Error/Page500

What happens
I get a blank page with nothing.

What I have going
Web Config - This was suppose to handle page not found.
<customErrors mode="On">
  <error statusCode="404" redirect="~/Error/Page404" />
  <error statusCode="500" redirect="~/Error/Page500" />
</customErrors>
So this runs in Global.asax
void Application_Error(object sender, EventArgs e)
        {
            if (HttpContext.Current.IsDebuggingEnabled)
            {
                // Pick up the Exception Error
                HttpException httpException = new HttpException();
                RouteData routeData = new RouteData();

                // Get our current controller and action
                string controller = Request.RequestContext.RouteData.Values["controller"].ToString();
                string action = Request.RequestContext.RouteData.Values["action"].ToString();

                //We clear the response
                Response.Clear();
                Server.ClearError();

                // Validate the this controller is legit

                // If the controller exist, use it, or else use the error controller
                if (controller != null)
                    routeData.Values.Add("controller", controller);
                else
                    routeData.Values.Add("controller", "Error");

                // A good location for any error logging, otherwise, do it inside of the error controller.

                //We check if we have an AJAX request and return JSON in this case
                if (IsAjaxRequest())
                {
                    Response.Write("Your JSON here");
                }
                else
                {
                    if (httpException != null)
                    {
                        int httpCode = httpException.GetHttpCode();
                        switch (httpCode)
                        {
                            case 500:
                                Response.StatusCode = 404;
                                Response.ContentType = "text/html";
                                routeData.Values.Add("action", "Page500");

                                // Clear the error, otherwise, we will always get the default error page.
                                Server.ClearError();
                                break;

                            case 404:
                                Response.StatusCode = 404;
                                Response.ContentType = "text/html";
                                routeData.Values.Add("action", "Page404");

                                // Clear the error, otherwise, we will always get the default error page.
                                Server.ClearError();
                                break;

                            default:
                                Response.StatusCode = 404;
                                Response.ContentType = "text/html";
                                routeData.Values.Add("action", "Page404");

                                // Clear the error, otherwise, we will always get the default error page.
                                Server.ClearError();
                                break;
                        }

                        // We can pass the exception to the Action as well, something like
                        // routeData.Values.Add("error", exception);                        

                        // Call the controller with the route
                        IController errorController = new coastEnviromental.Controllers.ErrorController();
                        try
                        {
                            Response.TrySkipIisCustomErrors = true;
                            errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            Response.Redirect("Error");
                        }
                    }
                }                

            }
        }
Then the controller fires
public class ErrorController : Controller
    {
        public ActionResult Index()
        {
            return View();
            return View("Page404", "Error"); // Also tried
        }

        public ActionResult Page404()
        {
            return View();
        }

        public ActionResult Page500()
        {
            return View();
        }
    }
And I get a blank page.
I tried setting a break point on the View, but It never hits.
If it ain't broke don't fix it

AnswerRe: Error Page , 404, 500 [got it to work, not sure if its solved] Pin
jkirkerx20-Apr-17 11:40
professionaljkirkerx20-Apr-17 11:40 
QuestionDevelop a Module in ASP.NET Pin
Muhammad Bilal20-Apr-17 4:08
Muhammad Bilal20-Apr-17 4:08 
AnswerRe: Develop a Module in ASP.NET Pin
User 418025420-Apr-17 14:29
User 418025420-Apr-17 14:29 
AnswerRe: Develop a Module in ASP.NET Pin
John C Rayan21-Apr-17 4:57
professionalJohn C Rayan21-Apr-17 4:57 
QuestionYou have to be inside an Angular CLI project in order to use the serve command Pin
indian14319-Apr-17 14:15
indian14319-Apr-17 14:15 
QuestionC# Data access layer and business logic Pin
sellol19-Apr-17 2:08
sellol19-Apr-17 2:08 
AnswerRe: C# Data access layer and business logic Pin
Richard MacCutchan19-Apr-17 5:43
mveRichard MacCutchan19-Apr-17 5:43 
AnswerRe: C# Data access layer and business logic Pin
User 418025419-Apr-17 7:22
User 418025419-Apr-17 7:22 
AnswerRe: C# Data access layer and business logic Pin
vinuvasahanponniah19-Apr-17 22:28
professionalvinuvasahanponniah19-Apr-17 22:28 
SuggestionRe: C# Data access layer and business logic Pin
Lehlohonolo Jairus Shole9-May-17 3:01
Lehlohonolo Jairus Shole9-May-17 3:01 
QuestionDropDownList Pin
Member 1116162519-Apr-17 1:57
Member 1116162519-Apr-17 1:57 
AnswerRe: DropDownList Pin
User 418025419-Apr-17 7:25
User 418025419-Apr-17 7:25 
AnswerRe: DropDownList Pin
John C Rayan21-Apr-17 5:02
professionalJohn C Rayan21-Apr-17 5:02 
Questionerror in opening page Pin
amirsamanipoor17-Apr-17 19:07
amirsamanipoor17-Apr-17 19:07 
AnswerRe: error in opening page Pin
User 418025418-Apr-17 4:35
User 418025418-Apr-17 4:35 
QuestionCombine AngularJS with Signalr in C# project. Pin
Member 1056128817-Apr-17 12:46
Member 1056128817-Apr-17 12:46 
QuestionHow to interact windows forms app to asp.net c# web Pin
Zeyad Jalil17-Apr-17 2:18
professionalZeyad Jalil17-Apr-17 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.