MVC can't find my Areas page - c#

I created an Area in my application named Admin. It's pretty basic, looks like this:
Areas
Admin
Controllers
CompaniesController.cs
Models
Views
Companies
Index.aspx
AdminAreaRegistration.cs
When I try to view my Index page by going to /Admin/Companies, I get a "The resource cannot be found" message. I find it weird that I don't get any sort of error message.
I'm not sure what's going on here, has anyone come across this?

If you newly created Index.aspx, you need to "REBUILD" the solution or your web project. Build only compile your last changes and rebuild build everything from the scratch. I faced that problem when I started writing Asp.net MVC project.
Does it solve your problem?

Related

How can I get MVC 5 to render a View that is physically outside the Web Application Folder?

I am using ASP.NET MVC5 and I would like to render a view from a folder that is outside the application folder. I tried registering my own custom the VirtualPathProvider and I even created my own VirtualPathProviderViewEngine to support rendering pure html pages. I have the latter working but cannot get the former to work. When I navigate to the route in question, I want MVC to check the internal Views folder for the View and then if it is not found I want it to look in the external folder.
When I step through the code, FileExists gets called for files that are in the Views folder and then the ViewEngine code runs but for a View that lives externally, the FileExists check runs and then I get a 404 on the screen. It does not ever get into the ViewEngine code. I know I am missing something simple here.
I am attaching a screenshot of what the sample folder structure would be. Any help would be greatly appreciated.
You can override the VirtualPathProvider and the VirtualFile
Check this link for an Example

Errors with new MVC5 project in Visual Studio 2013.3

Wondering if anyone else has experienced this and what their solution was if so. In Visual Studio 2013 I create a new ASP.NET Web Application, leaving all the defaults as they are
In the next screen I pick MVC, adding folders and core references for MVC but not the other two options. Authentication is left at Individual User Accounts and I've unchecked the Host in the cloud option, as shown below.
The project wizard completes and I can see that there are 26 errors in it before I do anything else.
The first fix that removes a bunch of these errors is that the Views\Account\ _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml files contain invalid models so I change those as follows:
[My project name here is WebApplication1, substitute your own value]
In _SetPasswordPartial.cshtml:
From #model WebApplication1.Models.ManageUserViewModel to #model WebApplication1.Models.SetPasswordViewModel
In file _ChangePasswordPartial.cshtml:
From #model Microsoft.AspNet.Identity.ManageUserViewModel to #model WebApplication1.Models.ChangePasswordViewModel
That drops me down to 4 errors, spread across 4 files
1.
Line 68, ManageController.cs
return View(linkedAccounts);
The view RemoveLogin doesn't exist
2,3.
There are two errors _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml complaining about not being able to resolve the Manage action but when I debug and visit those URLs in the browser they work fine so I suspect they're in a route table somewhere. I have R# installed so sometimes that can be wrong if that's the case.
4.
The last one is that the _RemoveAccountPartial.cshtml has an error on line 15 where it complains about not having a Disassociate action in the Account controller, as far as I can ascertain this is to do with removing other authentication providers to the application.
Now I can fix all these by adding the required code but it just doesn't sit well with me that the templates don't work well out of the box. Are there fresh templates available or has anyone done the canonical write-up on how to get your template humming before you commence work properly on it?
EDIT 2014-11-13
I've just applied VS2013.4 and these issues appear to be fixed as part of it. If this is an issue for people then I suggest applying that update.
I do not know what is the root cause of these problems but after playing with the project the following seems to bring it to a consistent state:
Remove Views\Account\_SetPasswordPartial.cshtml
Remove Views\Account\_ChangePasswordPartial.cshtml
Remove Views\Account\_RemoveAccountPartial.cshtml
All these have counterparts under the Manage controller. And finally:
Remove the RemoveLogin() action method from ManageController. Make sure you only remove the GET method (lines 64 - 69), as the POST one is actually used. The list of logins is rendered by ManageLogins action.
Found out it's a known problem:
http://blogs.msdn.com/b/webdev/archive/2014/08/04/announcing-new-web-features-in-visual-studio-2013-update-3-rtm.aspx
When creating a default C# ASP.NET Web Application from MVC, WebAPI or SPA template with individual authentication, generated Views\Account\ _SetPasswordPartial.cshtml and _ChangePasswordPartial.cshtml files contain invalid model.
In file _SetPasswordPartial.cshtml,
#model .Models.ManageUserViewModel
Should be changed to:
#model .Models.SetPasswordViewModel
In file _ChangePasswordPartial.cshtml,
#model Microsoft.AspNet.Identity.ManageUserViewModel
Should be changed to:
#model .Models.ChangePasswordViewModel
Similar problems exist for generated VB projects as well.
In file _SetPasswordPartial.vbhtml,
#ModelType ManageUserViewModel
Should be changed to:
#ModelType SetPasswordViewModel
In file _ChangePasswordPartial.vbhtml,
#ModelType ManageUserViewModel
Should be changed to:
#ModelType ChangePasswordViewModel
I confirmed issue also in VS2013 Ultimate Update#3. Submitted bug report to Microsoft Connect under Visual Studio and .NET Framework section.

MVC 5 C# Paths change after publishing asp.net project

So this is going to bed a dumb question because I understand there is a simple solution, I just cannot figure it out....
At the moment I am running my MVC 5 project in visual studio 2013... Normally when I want to debug it I will just click run and the website will appear in the browser of my choice...
I just recently published it to my companys web server and now I am having all kinds of issues...
The website is just 15 buttons on the Home/Index page and I want to be able to click on the buttons and still run them on my localhost side and when I publish them, still have them find the right path..
Here is an example because I am not very good at explaining things...
I run it in visual studio my url is:
http://localhost:54641/Home/Index
I run my published site on the webserver my url is:
http://webserver/racklabels/dakkota/Home/Index
I understand this part, and in either case both of them work but when it comes to clicking on a button, or images.. the pathing is all weird and I dont understand it.
In visual studio I click my first button and my url becomes:
http://localhost:54641/RecieveTruck/AddFor
On my webserver I click it and it turns to:
http://webserver/RecieveTruck/AddFor
but gives me the 404 error because it is not the correct route ( which should be..
http://webserver/racklabels/dakkota/RecieveTruck/AddFor
)
This is how I have my button setup in my View (Index.cshtml) and I am wondering if this is what is causing the probelm (I am thinking that I may have to do it a different way other than using onclick)
<input type="button" name="receive" value="Receive Truck" style="cursor: pointer;" class="bodyText"
onmouseover="this.style.color='orangered';" onmouseout="this.style.color='black';"
onclick="document.location.href='/RecieveTruck/AddForm';">
Basically I would like for this to work regardless of how many folders I am deep after I publish it and when I click run in visual studio (so I can debug/test and just republish to the webserver when I want to update)
I have tried many different ways of sending the path... like '~/RecieveTruck/AddForm' (which just adds the ~ to the address) and '../RecieveTruck/AddForm' and just 'RecieveTruck/AddForm' but none of them find the actual root of where the project lives and just adds this to it...
Can anybody help me?
You can use
#Url.Content("~/Home/Index")
but this completely misses out the benefit of mvc routing.
if you want to generate urls for controller actions, it's much better to use
#Url.Action("Index","Home")
...so now if you set up some snappy routing rule, the url in provided by .Action will adjust automagically (such as omitting url parts that have default values in your routing rules).
You need to add "~" to the front of the url document.location.href='~/RecieveTruck/AddForm'
or if that does not work use document.location.href='#Url.Content("~/RecieveTruck/AddForm")'

error while integrating blogengine.net 2.0 to a website

I was integrating the blogengine 2.0.what i did is
created folder inside my project called blogs.
copied all the files from the blogengine.net 2.0 (web).
made changes in the web.config and changed master page path.
as per
http://www.ajaymatharu.com/integrating-blogengine-into-an-existing-site/
4.while running the project it is showing the error in styles.
the screen shoot of the error is...
screen shoot of the project solution explorer is.
web.config file...
Probably not the answer you're looking for but I would go the sub-domain route and avoid all of these issues completely. Also makes it easier to maintain and upgrade. Every time there is a BE upgrade you potentially face similar issues by trying to integrate it into an existing site.
Here's one I did already: http://homenetdirect.com/
All I had to do was customize the blog CSS to match that of the parent site - you might even create a "complimentary" design...

Validation of ViewState MAC Failed

Sorry if this is duplicate but I've been going crazy for the past two hours over this.
After changing the Master Page in ASP.NET MVC 1.0 application, I keep getting this familiar error when I try a postback without filling in the mandatory form elements which are validated by the server:
"Validation of viewstate MAC failed.
If this application is hosted by a Web
Farm or cluster, ensure that
configuration specifies
the same validationKey and validation
algorithm. AutoGenerate cannot be used
in a cluster."
The new page refers to a lot of jQuery code with lightboxes, superfish etc. Could that be a problem while doing a postback?
If I revert back to the original master, the error disappears and I'm able to validate form fields. Both masters are located in the same path.
I know a lot of other guys have faced this issue but I was unable to find anything which could help me.
Thanks.
Edited and added
After a little debugging, I've realized that a directive in the master page:
<% Html.RenderAction("menu", "nav"); %>
is creating the problem. The directive asks the "menu" action of the controller "nav" to inject a partial view Menu.ascx. If I delete this line from the new master page, everything works OK. My app's left bar navigation relies on this directive to work properly. Is there any way I can get around this? Very mysterious.
Are you using Html.AntiForgeryToken() anywhere on this page? Sometimes when I am testing locally with multiple different sites and / or port changes this will happen to me. If it does I clear my browser cache and it works just fine.
I did experienced the same problem two days ago. :)
A simple restart of the box has worked in my case so I did'nt investigate further.

Categories