MVC cache error page - c#

When there is a 404 error, my application redirects to page http://localhost:41083/hata/page-not-found
Once my page http://localhost:41083/iletisim/musterimiz-olun redirects to 404 page, even though I fix the error it still goes to 404 page, it does not hit the controller's action. However when I call the http://localhost:41083/Contact/CreateAccount page which is the same page without url rewriting it shows the page without any problem.
So is it caching the page by url? If so, how can I disable it? I am not using any output caching on the action and my site runs on IIS Express.
My Route Config and ContactController:
routes.MapRoute(
name: "musterimiz-olun",
url: "iletisim/musterimiz-olun",
defaults: new { controller = "Contact", action = "CreateAccount" },
namespaces: new[] { "OyakCorporate.Controllers" }
);
public ActionResult CreateAccount()
{
return View();
}

Using Redirect() instead of RedirectPermanent() in Application_Error() method on Global.asax solved the issue.

Related

ASP.NET WebForms - routing gives 'page not found error '

I am using asp.net routing and getting a 404 error.
If I do not use an id value then I can see page.
But I want to pass iddata with route and getting 404 Page Not Found error.
Not sure why we see error when we want to use parameters.
With Parameters (404 File or Directory not found error)
routes.MapPageRoute( "Product", "product/{id}", "~/Pages/Product.aspx" );
Without Parameters (Page Works)
routes.MapPageRoute( "Product", "product", "~/Pages/Product.aspx" );
UPDATED NOTE: I have tested all routes if i add product/{id}, contact/{id} or etc. It causes all the same 404 error.
URL: test.com/product > WORKS
test.com/product/{id} > NOT FOUND
try this with * query values
routes.MapPageRoute(
"Product",
"product/{Id}/{*queryvalues}",
"~/Pages/Product.aspx"
);

Program trying to load the cs.html file, giving a 404

I am getting a HTTP 404.
I don't know what I did that suddenly started causing this error. I changed the startpage, then it began reporting this error.
I have found the file RouteConfig.cs (guessing this is where the solution might be) which looks like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Member", action = "AddMember", id = UrlParameter.Optional }
);
The error I am getting says that the ressource could not be found, reports this URL:
http://localhost:53043/Views/Member/AddMember.cshtml
I noticed that it suddenly want's to look for the .cshtml file. But isn't this wrong?
The controller to the AddMember View looks like this:
public ActionResult AddMember()
{
return View();
}
If I rightclick on the AddMember.cshtml file, and choose View in browser, then the page show up just fine, and the URL looks like this http://localhost:53043/Member/AddMember
Any idea to how I can solve this pls?
If I rightclick on the AddMember.cshtml file, and choose View in browser, then the page show up just fine, and the URL looks like this http://localhost:53043/Member/AddMember
The expected url for any cshtml page (or ActionResult of a controller) in MVC C# is http://localhost:{port}/{controller}/{action}/{id} where id is optional as stated in the route config.
The way you're trying to view the page http://localhost:{port}/Views/{controller}/{action}.cshtml is the file directory of the view and not the way to view a cshtml file in the browser.
To view a result of any cshtml file, simply press F5, Ctrl + F5, or right click and view in browser, they all return same result. Good luck.
The URL is wrong , you cannot directly load the ".cshtml" file. In MVC , you need to call the controller method which then calls the view. If your controller name is "Member" and method name is "AddMember" then the URL should be listed as mentioned below. Hope This Helps!
http://localhost:53043/Views/Member/AddMember.cshtml

MVC C# Bad URL handling with multiple parameter

I am new to MVC. Actually, I am trying to handle the bad request for my application. I have added Application_Error method in Global.asax and also created a controller to handle the 404-page error. Now this works fine when my URL is like following.
https://localhost:44397/t/t/t
It shows proper 404 page I have set for the bad URL
But It shows again 404 page when my URL is something like following
https://localhost:44397/t/t/t/e
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Can anyone help me how I can restrict above URL? Following is my route.config code.
routes.MapRoute(
"ErrorHandler",
"ErrorHandler/{action}/{errorMSG}/",
new { controller = "ErrorHandler", action = "Index", errMsg = UrlParameter.Optional }
,
namespaces: new[] { "MyProject.Web.Controllers" }
);
You need to register an additional route at the end of all valid routes which would match any URL. Sample code below. This will handle all invalid requests to your application.
routes.MapRoute(
"AllInvalidRoutes",
"{*.}",
new { controller = "InvalidRoutesController", action = "Index" }
);

ASP.NET MVC5 - Routed page loads but doesn't fire

I'm trying to get the open authentication for google working in my application. Using information found in the comments of this answer: https://stackoverflow.com/a/23094155/526704
So I added this route to the top of my RegisterRoutes method:
routes.MapRoute(
name: "signin-google",
url: "signin-google",
defaults: new { controller = "Account", action = "ExternalLoginCallback"}
);
Before doing this, navigating to localhost:port/signin-google gave me a 404, but now it just gives me an empty page. When I navigate directly to /Account/ExternalLoginCallback, it sees it wasn't given any login data, so it returns me to the login page (per the logic in the controller). When I put a breakpoint at the top of the ExternalLoginCallback method, it fires when I navigate to it directly, but not when I load /signin-google.
Why is the route returning an empty page?
There must be some sort of built-in route for /google-signin. I didn't solve this exact issue, but I was able to get Google OAUTH working with information from this link:
http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

Home Index not loading when the application starts

I am working on an ASP.NET MVC3 application.
In the Views I created a folder named Home and a View named Index.
Then I created a Controller HomeController.
In the Controller I added:
public ActionResult Index()
{
return View();
}
but when I run the application I get this error:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
If I add to the address bar : /Home/Index the view loads normally.
How can I make the application automatically go to Home/Index when it loads?
Thanks for any help
You need to add a route to the Global.asax file that points to your path.
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Categories

Resources