run a website project on visual studio failed in local by http 404 not found page error
I have been working on a project and I left it for about one week,when I came back to it and I tried to run the project with Ctr+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771/Views/Home/Index.cshtml
and confronted with HTTP 404: not found Error. while my route config is like this BUT IT WORKS FINE IF I TYPE THE CORRET URL MYSELF in front of the r+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I started debugging the project and it seems the project never come to my HomeController
. I just have one controller named Home, and when I removed all the codes of my Home controller it still act the same. and the other thing which it seems wrong, it creates the URL http://localhost:53771/Views/Home/Index.cshtml
even before it comes to RegisterRoutes
function. the problem is all local and here is my global.asax if needed. I appreciate any help
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace ML_Projectname
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MvcHandler.DisableMvcResponseHeader = true;
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
}
}
asp.net-mvc visual-studio routing
add a comment |
I have been working on a project and I left it for about one week,when I came back to it and I tried to run the project with Ctr+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771/Views/Home/Index.cshtml
and confronted with HTTP 404: not found Error. while my route config is like this BUT IT WORKS FINE IF I TYPE THE CORRET URL MYSELF in front of the r+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I started debugging the project and it seems the project never come to my HomeController
. I just have one controller named Home, and when I removed all the codes of my Home controller it still act the same. and the other thing which it seems wrong, it creates the URL http://localhost:53771/Views/Home/Index.cshtml
even before it comes to RegisterRoutes
function. the problem is all local and here is my global.asax if needed. I appreciate any help
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace ML_Projectname
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MvcHandler.DisableMvcResponseHeader = true;
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
}
}
asp.net-mvc visual-studio routing
add a comment |
I have been working on a project and I left it for about one week,when I came back to it and I tried to run the project with Ctr+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771/Views/Home/Index.cshtml
and confronted with HTTP 404: not found Error. while my route config is like this BUT IT WORKS FINE IF I TYPE THE CORRET URL MYSELF in front of the r+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I started debugging the project and it seems the project never come to my HomeController
. I just have one controller named Home, and when I removed all the codes of my Home controller it still act the same. and the other thing which it seems wrong, it creates the URL http://localhost:53771/Views/Home/Index.cshtml
even before it comes to RegisterRoutes
function. the problem is all local and here is my global.asax if needed. I appreciate any help
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace ML_Projectname
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MvcHandler.DisableMvcResponseHeader = true;
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
}
}
asp.net-mvc visual-studio routing
I have been working on a project and I left it for about one week,when I came back to it and I tried to run the project with Ctr+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771/Views/Home/Index.cshtml
and confronted with HTTP 404: not found Error. while my route config is like this BUT IT WORKS FINE IF I TYPE THE CORRET URL MYSELF in front of the r+F5 , it redirect to a URL which is not defined in route config. like this http://localhost:53771
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I started debugging the project and it seems the project never come to my HomeController
. I just have one controller named Home, and when I removed all the codes of my Home controller it still act the same. and the other thing which it seems wrong, it creates the URL http://localhost:53771/Views/Home/Index.cshtml
even before it comes to RegisterRoutes
function. the problem is all local and here is my global.asax if needed. I appreciate any help
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace ML_Projectname
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MvcHandler.DisableMvcResponseHeader = true;
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
}
}
asp.net-mvc visual-studio routing
asp.net-mvc visual-studio routing
edited Nov 21 '18 at 16:35
neda Derakhshesh
asked Nov 21 '18 at 16:11
neda Derakhsheshneda Derakhshesh
513421
513421
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I don't believe there is any issue with your routing or your application. Visual Studio's default start action (view by right clicking project -> selecting properties -> selecting Web) is "Current Page". If you're viewing a razor view (such as your /Views/Home/Index.cshtml
) at the time you run the project in visual studio, visual studio will try to navigate to this resource directly. Directly requesting a razor view is not valid in the context of an MVC application and you end up seeing the 404 error.
To avoid this, you can set the start url to a specific URL (ex: http://localhost:53771
) or even simpler, open and view one of the server side files (ex: HomeController.cs
) before running your project via Visual Studio.
tldr version: this is an issue with a setting you have in visual studio, not an issue with your application code
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416178%2frun-a-website-project-on-visual-studio-failed-in-local-by-http-404-not-found-pag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't believe there is any issue with your routing or your application. Visual Studio's default start action (view by right clicking project -> selecting properties -> selecting Web) is "Current Page". If you're viewing a razor view (such as your /Views/Home/Index.cshtml
) at the time you run the project in visual studio, visual studio will try to navigate to this resource directly. Directly requesting a razor view is not valid in the context of an MVC application and you end up seeing the 404 error.
To avoid this, you can set the start url to a specific URL (ex: http://localhost:53771
) or even simpler, open and view one of the server side files (ex: HomeController.cs
) before running your project via Visual Studio.
tldr version: this is an issue with a setting you have in visual studio, not an issue with your application code
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
add a comment |
I don't believe there is any issue with your routing or your application. Visual Studio's default start action (view by right clicking project -> selecting properties -> selecting Web) is "Current Page". If you're viewing a razor view (such as your /Views/Home/Index.cshtml
) at the time you run the project in visual studio, visual studio will try to navigate to this resource directly. Directly requesting a razor view is not valid in the context of an MVC application and you end up seeing the 404 error.
To avoid this, you can set the start url to a specific URL (ex: http://localhost:53771
) or even simpler, open and view one of the server side files (ex: HomeController.cs
) before running your project via Visual Studio.
tldr version: this is an issue with a setting you have in visual studio, not an issue with your application code
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
add a comment |
I don't believe there is any issue with your routing or your application. Visual Studio's default start action (view by right clicking project -> selecting properties -> selecting Web) is "Current Page". If you're viewing a razor view (such as your /Views/Home/Index.cshtml
) at the time you run the project in visual studio, visual studio will try to navigate to this resource directly. Directly requesting a razor view is not valid in the context of an MVC application and you end up seeing the 404 error.
To avoid this, you can set the start url to a specific URL (ex: http://localhost:53771
) or even simpler, open and view one of the server side files (ex: HomeController.cs
) before running your project via Visual Studio.
tldr version: this is an issue with a setting you have in visual studio, not an issue with your application code
I don't believe there is any issue with your routing or your application. Visual Studio's default start action (view by right clicking project -> selecting properties -> selecting Web) is "Current Page". If you're viewing a razor view (such as your /Views/Home/Index.cshtml
) at the time you run the project in visual studio, visual studio will try to navigate to this resource directly. Directly requesting a razor view is not valid in the context of an MVC application and you end up seeing the 404 error.
To avoid this, you can set the start url to a specific URL (ex: http://localhost:53771
) or even simpler, open and view one of the server side files (ex: HomeController.cs
) before running your project via Visual Studio.
tldr version: this is an issue with a setting you have in visual studio, not an issue with your application code
edited Nov 21 '18 at 19:22
answered Nov 21 '18 at 19:16
GregHGregH
2,65711651
2,65711651
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
add a comment |
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
it seems fine. thank you very much
– neda Derakhshesh
Nov 22 '18 at 11:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416178%2frun-a-website-project-on-visual-studio-failed-in-local-by-http-404-not-found-pag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown