MVC Resource Can not be found After Publish - c#

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!

Related

Is there any way to check with Browser name in RouteConfig.cs file?

I have tried to check the browser in RouteConfig.cs file, but its showing error that didn't get the request from browser.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
string browser = HttpContext.Current.Request.Browser.Browser;
if (browser == "Chrome" || browser == "Firefox")
{
routes.MapRoute(name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Login",
action = "Index",
id = UrlParameter.Optional
});
}
}
My goal is to access applications only from chrome and firefox, so I have tried to check it in RouteConfig to re-route to another view if condition not satisfied. But it's not working so I have checked with Global.asax but the routing is not working there.
You can't check for the browser at startup, since the startup isn't related to a request, so no browser to check there.
The best option you have is to check in the action or controller itself what the browser is. I would be wary though to exclude specific browsers form visiting your site, as it looks like you are trying now.
For browser-checking, a good option is to configure a middleware class that you can use to check each http request, and potentially specify a redirect or response. It is a suitable way to contain this logic all in one place, so you don't need to duplicate across controllers or actions, and is really easy to set up. Lots of articles are available online.

mvc4 resource not found error

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

ASP.NET MVC 404 not found error in prod but not in test

I have an ASP.NET MVC 5.2.3 website. I have been trying to add a link to a sitemap for it in the lower right-hand corner. The link is implemented in _Layout.cshtml using:
<p class="notep right">#Html.ActionLink("Site Map", "SiteMap", "Home")</p>
I see the web page appear beautifully on my local machine. But when I put it on the server I get:
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: /Home/SiteMap
I had this problem initially on my local machine as well. But there I fixed it by adding the code block:
public ActionResult SiteMap()
{
return View();
}
to the HomeController.
I can confirm that this change uploaded successfully to the website as well.
All the other action links on the website work perfectly. And so does this one on my local machine. So what might be different about the production environment that would prevent it from working correctly there?
EDIT
My RouteConfig file is:
using System.Web.Mvc;
using System.Web.Routing;
namespace MyNamespace
{
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 },
namespaces: new string[] {"MyNamespace.Controllers"}
);
}
}
}
EDIT
My project type from my csproj file is:
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
I certainly see my bin and obj directories in the document root, as well as other likely build artifacts.

WebApi doesn't get published?

I currently have two controllers. One is MVC and the other is a WebApi controller.
I've published these two with ease on the IIS server with the following settings:
WebApiConfig:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
RouteConfig:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "MVCControllerName", action = "MVCControllerName", id = UrlParameter.Optional }
);
Now I've added another WebApi controller, but when published, the webserver says:
No HTTP resource was found that matches the request URI
http://example.com/folder/api/Other?id=45&text=bla
Implementation of the OtherController:
public void Get(int id, string text)
{
// something simply gets commited to the DB
}
Also, something weird is happening when publishing... I've deleted the first WebApi controller from the solution, but for some reason when publishing I can STILL call that WebApi through HTTP GET request! Even though it's gone!
OTOH, it works fine in the debug mode..
What's going on here?
EDIT: It seems the problem is not in my code, but in VS' publishing feature. It has always worked until now. I had to manually copy the files to the server, which isn't the point of so-called "one-click publishing". Other similar SO questions seem to indicate it is a VS bug that is still not fixed in SP2.

Mvc2 Controller not firing default action when url specifies only directory

Have an MVC 2 app with default route:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
This works great for everything we have except for one controller. When we browse to the url http://myserver/ThisOneController it doesn't fire the Index action and gives a 403.14 forbidden error. If I surf to http://myserver/ThisOneController/Index it works fine! Every other controller shows the expected behaviour.
The controller in question has an Index action method defined and viewing the folder in IIS seems to show no differences between that and other folders. It works in our production box but not on our test boxes...for the life of me, I can't find any differences between those boxes.
Any ideas?
Add Glimpse to your project and check what route is being used. You can then find out if the problem is in your MVC app or the environment.
This is expected behavior.
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
The above route means, you expect a controller/action/id, and the default (when nothing is provided) is root/Home/Index/. So any other controller with url like root/diffController/ is not matched, since you are providing a controller, but no action.

Categories

Resources