Account model in MVC app doesn't work after deployment - asp.net-mvc

I have an MVC app that I deployed to test on my machine (IIS on XP). I am unable to login using credentials I have set up using the ASP.NET configuration. Everything works fine before I published app. After typing in my username and password, the app doesn't seem to recognize it and gives the follwoing error message
![enter image description here][1]

By default, a new MVC project is configured to use the Membership Provider with SQLExpress using a file called aspnetdb.mdf in your App_Data folder. When you published, did that file make it to the destination?
To verify this is the issue, check your web.config. Look for the membership tag and the providers tag underneath that. Locate the AspNetSqlMembershipProvider provider and check its connection string. It will likely say ApplicationServices if you haven't changed it from the default. Then, check the ConnectionStrings node in your web.config to verify what database the Membership Provider is trying to use and where it's located.

Related

How can I publish/upload ASP.NET MVC 5 Website

I have never published an ASP.NET MVC website to a hosted server. I have read and followed instructions and failed with publishing from Visual Studio directly to the hosted server. I used FTP publish method, provided required credentials, then published the website successfully. When I do this, I get the error when I try to access the website:
500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.
I thus followed another instruction to publish to a local folder, using File System method, then uploaded the contents of that local folder using ftp to the hosted server. This gives me this error when I try to access the website:
Server Error
403 Forbidden
You do not have permission to access this document.
I would have loved the second method to work, but looking at the folder content, I can see some folders like App_Start missing, which I know is where start up pages are managed from, so I am not sure whether this is a proper procedure.
I would love some advice on how to publish this website. It would also be great to find a way that will allow updating changes, instead of publishing the entire website whenever changes are made.
I am using VS2019, and a .net hosting provider, not Azure.
Thank you!
In most case you can't see App_Start but all can working fine, you should find httpdocs it's the destination folder that you need to use to copy your files.
You can also try web deploy in your visual studio.
To make it work correctly you need to get the setup file from your hosting provider, with this you don't need to update always all files by ftp, and if you are lucky (if you have Database rights) you can also auto-update your database.
Don't forget also to check your web.config if you use a database connection.
Please try this two methods then if you need more help I will edit.

How to publish ASP.NET MVC on IIS server

I am struggling with trying to publish a site.
I have made a basic web site with ASP.NET MVC and I now want to host it on a pc.
I have opened ISI manager and added a new site. I set the default directly to the directly where the files for the site are stored but when i navigate to the pc I don't get my site. I get an IIS server error in application error.
What steps do i need to do to get the a basic site to run on the server.
First, you need to have installed iis, this is done you have to register the asp.net framework, for this you need to run a command line.
Go to cmd and type:
aspnet_regiis -i
Done so please enter
http:// localhost/AplicationName
If you get an error, then you should really post that error with your question. However, since the most common problem in the scenario you describe is permissions, I'm going to assume that that is your problem.
Unless you're going to put your code in a directory owned by IIS (such as "inetpub"), then you need to give the IIS user or group rights to the directory your code is in. You can do this by right-clicking the directory in Windows Explorer, and choosing "Properties". Then click the "Security" tab. Use the "Edit..." button to add the IIS user or group. It should be named something along the lines of "IIS_*". You'll need to grant full control, so just like any other publicly available directory (including "inetpub"), you should ensure that there's nothing secure or compromising in that directory.

Unable to get windows authentication to work through local IIS

So I've created a new ASP.NET MVC project using the intranet template. web.config contains the appropriate values (e.g. <authentication mode="windows"/>).
If I fire up the web app using the VS webserver, it all looks fine - the page shows my Windows domain and username and all. However, this works in Opera and Safari as well as IE and FF, which says to me it's not using Windows auth at all (since to the best of my knowledge this doesn't work in any browser except IE/FF).
Next step is to get it working through local IIS. I create a hosts file entry pointing www.mysite.mydomain to 127.0.0.1. So in IIS I create website with a binding to www.mysite.mydomain and enable Windows authentication and disable anonymous authentication.
I have set up IE and FF to enable Windows auth as follows:
IE
Add URL to intranet group
Ensure Windows auth is enabled in the advanced settings
FF
Put 'www.mysite.mydomain' into network.automatic-ntlm-auth.trusted-uris config setting.
But when I dial up www.mysite.mydomain in IE / FF I get a login prompt. Interestingly, even when I type in my Windows login here, it still fails and shows me the login prompt again.
We don't have active directory here but my understanding is that it should work fine with a local account.
I can't think of anything else I need to do. Any suggestions?
Edit: we've recently switched to using Active Directory and the problem remains.
Edit: when I cancel the login prompt, I get taken to an 'IIS 7.5 Detailed Error' page with the following information:
HTTP Error 401.2 - Unauthorized
You are not authorized to view this page due to invalid authentication headers.**
You have to whitelist a domain specified in the hosts file in order for windows authentication to work:
Click Start, click Run, type regedit, and then click OK.
In Registry Editor, locate the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Right-click Parameters, click New, and then click DWORD (32-bit) Value.
Type DisableStrictNameChecking and press ENTER.
Double-click the DisableStrictNameChecking registry value and type 1 in the Value data box, click OK
In Registry Editor, locate and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Right-click MSV1_0, point to New, and then click Multi-String Value.
Type BackConnectionHostNames, and then press ENTER.
Right-click BackConnectionHostNames, and then click Modify.
In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK.
Quit Registry Editor, and then restart the IISAdmin service.
NOTE:
The original Microsoft KB links on this answer were broken and have been removed.
This article provided the instructions for setting DisableStrictNameChecking.
I recently spent three days trying to solve the same problem and it drove me crazy. It was happening on a load-balanced setup where one of the servers was authenticating correctly while the other failed. Investigating the problem - and eventually solving it - it turned out to be unrelated to the load-balanced environment, it could happen with any server when authenticating using Windows Authentication and the server is called with a name other than the one recognized by Active Directory
1. Enable Kerberos logging
To correctly diagnose your issue, you will need to enable Kerberos logging on the machine hosting your IIS site. To do so, add the following registry entry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters
Add Registry Value LogLevel with ValueType REG_DWORD and value
0x1.
Once you turn on logging, then you try to authenticate, you will get errors logged in your Windows Application Log. You can ignore the error KDC_ERR_PREAUTH_REQUIRED (this is just part of the handshake) but if you get the error KDC_ERR_C_PRINCIPAL_UNKNOWN that means your AD controller doesn't recognize your server therefore you need to follow the steps below.
2. KDC_ERR_C_PRINCIPAL_UNKNOWN
if you're getting KDC_ERR_C_PRINCIPAL_UNKNOWN, that means the name "mysite.mydomain.com" is different from how the AD recognizes your machine so it's unable to provide a valid kerberos ticket. In that case, you need to register a Service Principal Name (SPN) for " 'www.mysite.mydomain" on the AD.
On your AD controller, run this command - you will need Domain Admin privilege:
Setspn -A HTTP/mysite.mydomain YOUR_MACHINE_HOSTNAME
3. Use a custom identity for your Application pool
Finally, make you Application pool use a custom account that belongs to the Active Directory instead of using NetworkService. This can be done in advanced settings of your application pool.
and .. voila.
Notes: The problem could (unlikely) be related to having multiple SPNs registered to the same machine, in that case you will need to run a command to remove duplicate SPNs, but I doubt this is the case. Also try adding a different binding to your site (that doesn't use a custom name) something like htttp://localhost:custom_port_number and see if authentication works. If it works, this is an extra indication that you're suffering from the same problem I had.
Did you try putting the domain in front of the user name?
DOMAIN\username
If you don't have a domain account, try prefixing your username with the machine name:
MYCOMPUTER\myusername
You should check to see if you have Windows Authentication installed/enabled. That may sound weird but in IIS 7 you have to install and enable the various authentication methods. Check out http://support.microsoft.com/kb/942043/ for more info, see quoted section below.
Cause 1
The Web application is configured to use Integrated Windows
authentication. However, the Windows Authentication feature is not
turned on. Or, the Integrated Windows authentication native module
section of the ApplicationHost.config file or of the Web.config file
is not valid. To resolve this problem, see Resolution 1.
Original
Usually when you try to view an asp.net web page hosted on IIS and receive a login prompt it doesn't mean your credentials weren't received or that you aren't authenticated. What it means is that the account that your website is running under doesn't have the right permissions to work with the files.
In IIS 6 and 7 you can easily change the user account that your app pool runs under. Try changing the app pool identity to an account with more access specifically designed for this. Or if you want to stick with the existing account (IUSR_? Network Service?) you can grant that account more permissions on the directory where your website is stored.
This article is specifically targeted at BizTalk but has almost no references to it and focuses on troubleshooting permissions issues with IIS and app pools: http://msdn.microsoft.com/en-us/library/aa954062.aspx
Why local IIS? Can you use local IIS Express?
If so, try this. It seems that IIS Express by default has Windows Authentication set to false.
Change
<windowsAuthentication enabled="false">
to "true" in applicationhost.config file (under 'C:\Users[Profile]\Documents\IISExpress\config' folder). This works for me.
To ensure that IIS uses Windows Authentication, I think you should try to turn of other authtentication methods. If Anonymous Authentication is enabled, Windows authentication will not work. You can also read this Microsoft Support Article which describes IE and IIS requirements in details.
I got this error when I enabled Windows authentication. I wanted to authorize the user based on Windows login and there is no login page in my application.
I got the error fixed by adding the below in my Web config file.
Under the tag system.web, I changed authentication mode="None" to
authentication mode="Forms".
Under the tag appSettings, I added add key="owin:AutomaticAppStartup" value="false"
After reading the answer of Espen Burud, I solved my problem by changing in the root's web.config:
<allow users="*" />
to
<deny users="?" />
The page that needs Windows Authentication is not in the root, but in a sub directory with its own web.config with deny users ? but that did not make Windows Authentication working. Apparently, you need to deny users in the root for that to work.
The IIS config has Anonymous Authentication enabled; that did not matter. After the above change of web.config, Windows Authentication worked.
For Dot Net Core 2.2 and running on IIS, I was having issues with 401.2 Unauthorized when I would check the Enable Windows Authentication within my application. It was a exceedingly simple test website that did basically nothing, just to try and get windows authentication to work. I finally got the auth to work, and here's what you'll need:
Within Startup ConfigureServices:
services.AddAuthentication(IISDefaults.AuthenticationScheme);
Open the application's Properties, click Debug option on the left and make sure you check Enable Windows Authentication.
But here's the kicker that I had forgotten... Configure your system to have Windows Authentication installed on IIS. This was never setup on my machine, and regardless what I did, I would always get a 401 unauthorized error. After installing this (Win 10, IIS v10.0.18362.1) I now get a login prompt. This isn't exactly what I need at this point, but at least it's not the unauthorized error. Good luck and hopefully this helps.

When hosting an azure MVC app, my web.config's appSettings collection is empty

Using MVC 1.0, and Azure July 2009 SDK
I have an MVC application that appears to be working in the azure test framework, except for the fact that my appSettings collection is empty when running there. (But if I just run the web project on it's own, it's fine.)
Is there something special I need to do to access the web.config from Azure?
Sounds quite odd... I might check that web.config is getting properly copied when you launch under the dev fabric. Browse to your app directory and look for a .csx directory. Under there you should find your web app and hopefully the correct web.config. If not, then the problem is somewhere in packaging. (Make sure that web.config is marked as "content" or "copy always" in the properties in VS.)
Otherwise I'm happy to take a look at the project if it's something you can share. My email address is Steve.Marx#microsoft.com.

Can you run an ASP.NET MVC application from its project folder?

In IIS 5.1, I have setup a website to point to my ASP.NET MVC project directory, and I get a "Service Unavailable" error when I try to access it after building the project. It seems I have to publish the site to a separate directory and point IIS to the published version to get it to work.
I have already tried "aspnet_regiis" but that did not fix the issue. I have also setup wildcard mapping so all requests are sent through the ASP.NET pipeline.
I'm not sure why I would have to publish the files in order to view them. The published version appears to only remove unnecessary files, but the published files seem to be identical to the ones in the actual project directory.
Do you have to publish an ASP.NET MVC website to a different directory in order for IIS to serve it?
Ideally, I would want to set it up such that all I have to do is build the project, and I can immediately view the updated website by visiting localhost.
Update:
The version is set to 2.0, and when I get home I will check if the IUSR account has sufficient privileges. I can't imagine why it wouldn't because the published folder apparently had them by default.
Update #2:
The errors in the event log are:
Failed to initialize the AppDomain:/LM/W3SVC/1/Root
Exception: System.IO.FileLoadException
Message: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.
and
Failed to execute the request because the ASP.NET process identity does not have read permissions to the global assembly cache. Error: 0x80070005 Access is denied.
I have given the MY_MACHINE\ASPNET account "Act as operating system" privileges and I still get this error.
Update #3:
So this is interesting... I have XP Media Center Edition, so I forgot I don't have a security tab to verify permissions.
I decided to copy and paste the entire solution into a newly created folder and it works perfectly. This indicates that it's a permission issue but not with the ASPNET user. I will try to activate the Security tab and make a 4th (and hopefully final) update.
Update #4:
It turns out that when I copied the directory, the permissions changed to allow Everyone access to it. When I checked the original project directory, the ASPNET user was not granted any permissions in the directory.
The simple solution was to grant the ASPNET user read privileges on the project directory.
No problems at all. I've been running an MVC app on IIS5.1 for 6 moths while developing it.
First off check the version of ASP.Net used for your site.
If that isn't the problem check that the user account used to run your website has permissions to the directory and all the files and folders contained within it and make sure that the network service has permissions.
take a look at this link - which might help:
http://weblogs.asp.net/bdesmond/archive/2003/09/20/28441.aspx

Resources