I have a MVC application, I try to run the application but I can not get any page in Browser, I am guessing the path has some problem.
This is RouteConfig:
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
routes.MapRoute(
name: "Default", // Route name
url: "{controller}/{action}/{id}", // URL with parameters
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}
This is HomeController:
public ActionResult Index()
{
ViewBag.Message = "Welcome to DevExpress Extensions for ASP.NET MVC!";
return View();
}
This is the View's path:
Views -> Home -> Index.cshml
#Html.DevExpress().ReportDesigner(settings =>
{
settings.Name = "ReportDesigner";
}).Bind(new DevExpressDemo.Reports.Report1()).GetHtml()
This URL is in Project URL: http://localhost:53975/
When I run the project I go to this URL:
https://localhost:53975/Home/Index
But this is the response I am getting in Browser:
This site can’t provide a secure connectionlocalhost sent an invalid response.
When I go to http://localhost:53975/ it convert it automatically to https and shows : This site can’t provide a secure connection
You are trying to access it through https rather than http. Go to http://localhost:53975 in your browser and see if that works.
change HTTPS to HTTP on yourr brrowser address bar
Related
I am getting the following error when debugging my header links.
I have tried recreating my Index.cshtml (Empty and with Razor/HTML) and my ServicesController.
If I browse to Services/Index explicitly then the page loads up correctly.
IE: localhost:58069/Services/ does not work but localhost:58069/Services/Index does
My other controllers are working correctly using the same structure and ActionLink helper.
Not working code:
public class ServicesController : Controller
{
// GET: Services
public ActionResult Index()
{
return View();
}
}
Action Link HTML Helper for Services/Index
<li>#Html.ActionLink("Services", "Index", "Services")</li>
Working Code
public class HomeController : Controller
{
// GET: Home/Index
public ActionResult Index()
{
return View();
}
}
Working Helper
<li>#Html.ActionLink("Welcome", "Index", "Home")</li>
Route Config
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Tried the following SO solutions:
ASP MVC in IIS 7 results in: HTTP Error 403.14 - Forbidden
This behavior is caused by the Services folder (below Scripts folder) you have in your project. When hosting in IIS, you should not have a file or folder with the same name as your ASP.NET route.
Ways to solve this:
routes.RouteExistingFiles = true; will let ASP.NET handle all the routing
Rename your Services folder or controller
Move Services to a separate library and remove the folder from the web project
I'd recommend the latter option as settings RouteExistingFiles to true would need additional research to double-check you're not opening any security holes and it cleans up your web project (a little bit of separation never hurts).
All, I have an ASP.net MVC application (using DevEx controls). I have deployed to a test server via IIS. When I run the application it gives the below pop up for the home page.
testserver:1234
If I navigate to other pages, testserver:1234/page1 , testserver:1234/page2 it works.
has anyone encountered same issue? Do you know why am I getting this pop up on home page testserver:1234. Thanks for helping out.
This how my controller looks:
public ActionResult Index()
{
ImportDataValidationErrors = new List<ImportFileRecord>();
return View();
}
and this is how routing looks:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ImportData", action = "Index", id = UrlParameter.Optional }
);
}
There are a bunch of similar questions, but none of the answers have worked me. I'm try to return 'RedirectToAction("Index");' which is in the same controller, from 'public ActionResult Create()' when the user is not authorized to create a new widget. I have no other folders with the name Index, although there are other 'Public ActionResults Index()' functions in other controllers. Any suggestions wouls be greatly appreciated...thanks
I have tried to replicate your scenario to no avail.
New MVC5 project with a Test controller tried both Authorize attribute on both actions just to test, but all they do is actually redirect you to the login page if you are not authorized to view the resource.
HTTP 403.14 is a code for directory listing denied.
It sounds to me that you are redirecting to a URL that is not being handled by the MVC and instead is being picked by your IIS express, which by default doesn't allow listing of directory contents.
So questions to consider are:
1: what is the exact url that you are calling.
2: How is your routing setup, do you have any custom routes ? order of the routes is important.
To be able to provide you with more info please do post the controller code as well as your RouteConfig.cs file.
Here is the test code.
public class TestController : Controller
{
// GET: Test
[Authorize] // just redirects back to login page if you call create action.
public ActionResult Index()
{
return View();
}
// GET: Test/Create
public ActionResult Create()
{
return RedirectToAction("Index");
}
}
Here is the routes config file. unchanged.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
my requirement is, there will be one controller method, which will handle all the request, that might return MVCview/model, or it might return .ASPX page, in any case URL must be same.
something like following.
public ActionResult HandleRequest()
{
if(Module is Converted)
{
return view(ModuleName);
}
else
{
//return module.aspx page, Here I can user Redirect method but it will change URL
//I don't want browser's Url to be changed.
}
}
Your answer is Routing.
http://msdn.microsoft.com/en-us/library/cc668201.aspx
Look at following code :
public ActionResult Test()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return RedirectToAction("TestAspx");
}
public ActionResult TestAspx()
{
ViewBag.Message = "Your app Test aspx page.";
return View();
}
Here the action TestAspx() returns an TestAspx.aspx view.
And for the Routing
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"TestAspx",
"testganesh",
new { controller = "Home", action = "TestAspx" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
}
Please make appropriate changes to the routing names that you need.
Hope this will help.
Let me know if you still face any issue.
Mark as right if the issue got fixed.
:)
I would like to suppress the controller from the route, and it worked fine using this:
routes.MapRoute(
name: "HomePages",
url: "{action}",
defaults: new { controller = "Home", action = "Index" }
);
The problem is when doing the same for a different controller like "Account", the first option only will take effect :
routes.MapRoute(
name: "LoginRoute",
url: "{action}",
defaults: new { controller = "Account", action = "Login" }
);
My objective is to hide the controller from the route, so i can directly access mysite.com/login and mysite.com/index, how to achieve that when login is under Account controller and index is under Home controller?
How to specify the second option for the Account actions, and keep the first for the Home actions?
Have you thought about using the Routing attributes e.g:
[Route("{getId:int}")]
public ActionResult Show(int getId) { ... }
you can use this in conjunction with the old way of routing. You do need to explicitly set this functionality in your config:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
}
I have found the routing Attributes makes it very easy to set good routes on my controller methods. This also bleeds into web api and RESTFul stuff as well.