Why does the url http://udine.bioen.utah.edu/EarlyAdmits/Admin work, while the supposedly equivalent url, http://udine.bioen.utah.edu/EarlyAdmits/Admin/Index, give an error: The resource cannot be found?
you have to check route configuration, may be is not configured correctly
First Check Index page Exist in Admin Controller Or not ??
If Yes Then
May Be you Have Applied Form Authentication In Your Project For the Security Purpose Which Is Not Allowing You To Direct Access Of Index Page.
In Form Authentication When You Login On Page Ticket is Generated For the Security..And For The SubSequent Request Every Time It check The Availability Of ticket Before Rendering any Page..
You Try To Access Index Page So I think It will Not Render..
The problem is solved by adding an explicit route equivalent to the default route. But I still don't understand why the default route doesn't work.
Below is my RouteConfig.cs file:
using System.Web.Mvc;
using System.Web.Routing;
namespace AdmitsWebsite
{
public class RouteConfig
{
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 }
);
routes.MapRoute(
name: "Export",
url: "Admin/Export"
);
}
}
}
Without the explicit route trying to access Admin/Export give a "resource not found" error
Related
I'm trying to access an app on my localhost connected to IIS with the following endpoint I'm trying to hit https://api.url.com/api/tab. I have a TabController.cs in my Controllers folder. I also have a Views/Tab/Index.cshtml file and am wondering why I'm getting the following two errors:
<Error>
<Message>No HTTP resource was found that matches the request URI 'https://api.url.com/api/tab'.</Message>
<MessageDetail>No type was found that matches the controller named 'tab'.</MessageDetail>
</Error>
I have the same folder structure for a controller named Footer, and I'm able to access https://api.url.com/api/footer successfully. I've included my WebApiConfig.cs and RouteConfig.cs code below:
WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
RouteConfig.cs
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 }
);
}
I've a feeling it's something quite obvious I'm missing as I'm a bit new to .NET and the MVC structure. So any point in the right direction would be greatly appreciated.
You trying to access the MVC Controller (inherited from the System.Web.Mvc.Controller) as if it's the Web API Controller (inherited from the System.Web.Http.ApiController). As you know API controllers have their own routing configuration, which is completely separate from the rest of
the application. Therefore, to access an action method from the regular MVC controller don't use api prefix in the URL. Just enter https://api.url.com/tab to call the default action method in the tab controller.
I have an MVC Web Application.
When I am running the application from my code, that works fine and I am able to go any pages.
However I publish it on IIS, It gives the 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.
And the URL Changes like below:
http://localhost/IssuerScripting_Web/%23/%23
However the path is
http://localhost/IssuerScripting_Web/UserRoleManagement/User_Management
EDIT: Here is my RouteConfig in below.
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Dashboards", action = "Dashboard_1", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Password",
url: "AdminUserPasswordCreate/PasswordCreate/{id}/",
defaults: new { controller = "AdminUserPasswordCreate", action = "CreatedPassword", id = UrlParameter.Optional }
);
}
And the below is the controller of Dashboard:
public class DashboardsController : BaseController //BaseController
{
public ActionResult Dashboard_1()
{
return View();
}
}
What might be causing this issue?
My default login page is working fine. But this page is like a main page and has all the Menu Items.
I was able to publish it earlier, and was working when I publish. I am not able to figure out the issue.
I will be thankful for any help.
To whom has this problem, After several hours I figured out that Scripts files were not pasting properly when I published it.
I removed the Scripts, Styles, Content folders from my project and added them back.
Then I published and it worked!
I have an issue in Routing in MFA where link like
Project_Name\Controller\Index is working, whereas
Project_Name\Controller\ is not working
This is happening for only some controllers after being deployed in a server.
I am getting the following error:
403 - Forbidden: Access is denied.You do not have permission to view this directory or page using the credentials that you supplied.
Is there any further configuration values that needs to be considered?
In RouteConfig we define the route path like this
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
So the controller you are using may have Index action method and the URL works.
But if your controller does not contain Index method or it is having parameters then it will not work.
This is a possible solution that you might create an action method named Index in all those controllers.
for more, you need to share some more details.
I just created a new ASP.NET MVC 3 project with the Razor engine. I added a controller to the controller folder, and then at homController.cs I added a view.
The View (index.cshtml) has only this code:
#{
ViewBag.Title = "Home";
}
<h2>Home</h2>
And when I start debugging it shows me this error:
Server Error in '/' Application.
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: /
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
What's the problem?
Could you check the App_Start/RouteConfig.cs, you must have this code for a controller called homController.cs :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "hom", action = "Index", id = UrlParameter.Optional }
);
}
I suppose, your first controller name isn't 'Home', so you have to change the default controller name !
Check your routing entries in Application_Start in global.asax since you're using MVC 3. like "Joffrey Kern" suggested, you need to have the routes configured.
also make sure your controller is named "HomeController" and you have a public method called "Index" that returns an ActionResult object.
In ASP .NET MVC 3 your routes are defined in the global.asax
You can find that in the website root.
By default it looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
This means when you call the website root with no parameters, it uses the default values - in this case home/index.
So you need to make sure you:
have a controller called home
an Action called index that returns an ActionResult
Alternatively you can update the default values in the routes, although if you are just starting out I would not recommend this.
It doesn't have to be your routes ... It could be faulty configurations in web config
If you getting this error I highly recommending you to change your public class name. Give a new name as a "HomeController":
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MyFirstMVC.Controllers
{
public class HomeController : Controller
{
// GET: /First/
public string Index()
{
return "Jay Swaminarayan"; // this string will be display at your run time!!!
}
}
}
THis is ravinder akula
Please find this answer
Right click on your mvc project
Choose "Properties"
Select the "Web" tab
Select "Specific Page"
Assuming you have a controller called HomeController and an action
method called Index, enter "home/index" instead of
home/index.cshtml in to the text box corresponding to the
"Specific Page" radio button.
A specific page in my web application has a URL www.example.com/Test/Index
However, I want to make this URL accessible when the user simply inputs www.example.com/Test instead of the whole thing.
So how can this be done using C# alone? Any help will be highly appreciated!
You can use a redirect. In ASP.NET this is Response.Redirect. In MVC this is RedirectToAction("Index"). This will cause their browser to then request the other URL.
If you want the URL to not be changed/redirected, and show www.example.com/Test, then you can use a server side redirect. ASP.NET: Server.Transfer. In MVC you can just return Index(); but this can be problematic sometimes. A better option is to use a default route:
public class MvcApplication : System.Web.HttpApplication
{
...
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Test", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
You should get this code automatically with any newly created MVC 3 application. you just have to custimize it for the controller you want to respect this default route.