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.
Related
We have an app built on dotnet core (currently 5, will be upgrading to 6 soon) that has a very strange issue. 95% of the web app runs perfectly, but there is a single razor page that generates a 404 - but only when deployed to the production server. Within Visual Studio it all works as expected, but even using dotnet MySite.dll (the .exe version of that command didn't work - it said a duplicate reference existed in the deps.json file with a different extension, but targeting the .dll version did what I expected) which spins up a "development" web server on ports 5000/5001, but even that gets the 404 on this one single page. All other pages work (including partial views) as expected.
The code on the page is about as basic as it comes, because it's a partial view setup like this:
#page "/providers/information"
#model ProviderInformationChangeRequestModel
#{
Layout = null;
}
The rest of the content on the page is just HTML - it's got a form, textbox and button on it, so nothing fancy there. Behind the razor page it's also quite basic:
public async Task<IActionResult> OnGet()
{
//EntityModel is a public property exposed on our base `PageModel` class (ours extends the Microsoft one)
this.EntityModel = new ProviderChangeModel();
//this is an API call - we use this exact call all over the site, so presumably it isn't failing, since it works everywhere else
var entity = await this.GetFromJsonAsync<ProviderUserModel>("/user/me");
this.EntityModel.ProviderUserId = entity.Id;
this.EntityModel.ProviderId = entity.ProviderId.Value;
return Page();
}
Every other partial view we have using this type of structure works - both deployed and through VS - and it's just this one page that won't work. I've read that this can sometimes happen when a Razor page makes backend API calls if one of those kicks back a 404, but the only call it makes is one we use throughout the site so it can't be that.
Does anyone have any ideas that can point us in the right direction? If it was failing in VS it'd be easy to track down, but since it's only the deployed version (which I've redeployed multiple times, restarted corresponding app pools and so on), I'm at a loss.
Well that was quick. A friend looked at it and realized the Build Type on the cshtml page was set to None instead of Content - how it worked in VS I'm not sure I understand, but at least it's solved now.
After login, in home/index, urls localization is inconsistent.
This is a solution (ASP.NET Core 2.2) that displays the problem
https://github.com/bonioloa/AspCoreLocalizedSite
Localization code is in the BaseController, Globalfilter, Setup. You can input any value on the field on Login page.
Localization should work by url and if you manually change it (example: localhost/it/Home/Index to localhost/en/Home/Index ) and then navigate with enter, I expect that all links generated in page will have a path starting with "en".
If you check source html of this page you can see that Home/Index have the correct path (/en/Home/Index) but Privacy and Logout paths start with the wrong language (/it/), all links are generated with the same asp tag (see _layout.cshtml view)
so after a good night sleep I changed approach and I finally noticed one thing:
SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
this directive was breaking localization routing for the first version of my code implemented using this articles
Link1
Link2
failing to realize that compatibility setting was the root of the problem i made a custom solution that was utterly bugged. Warning: that this setting is shipped with the default ASP.NET Core 2.2 blank solution by visual studio.
I deleted the repository and I recommend to use the template provided in the linked articles.
I have created a project using ASP.Net MVC 5, EF 6 and .Net 4.5.1
At some point I needed to change the namespace that the project is in, from "MyTestProject" to "MyRealProject".
After making those changes throughout the web site I now get several errors in a couple of my views.
_ChangePasswordPartial.cshtml can't find "#model Microsoft.AspNet.Identity.ManageUserViewModel" any longer and _SetPasswordPartial.cshtml can't find "MyRealProject.ManageUserViewModel"
No where in the project can I find a file that contains the class ManageUserViewModel. Before I changed the namespace it was found but now it isn't. Why? Where did it go and how do I fix it?
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
Also posted it here:https://stackoverflow.com/a/27687882/1071698. I don't know what the rules with duplicate questions and answers, please edit as necessary.
_ChangePasswordPartial.cshtml should use something like
#model MyRealProject.Models.SetPasswordViewModel
Then make sure in the models folder AccountViewModels.cs
The namespace is updated to MyRealProject.
Hope that helps.
CRTL + SHIFT + F , then type in "class ManageUserViewModel" , just that simple
make sure it is set to search entire solution , and it will find the class you are looking for
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")'
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?