ASP.NET MVC users not being copied over on publish - asp.net-mvc-2

I'm new to ASP.NET MVC, and I'm trying to convert a very simple ASP.NET application to MVC with authorization.
I have it working locally just fine, but when I publish to IIS, the users database is apparently not copied over correctly (even though it is running on the same machine that I am developing it on)
It does not appear to be a database access issue, since when I create a new user using the Register link I can log in just fine. The problem is, all the users (and their associated roles) I created using the ASP.NET Web Site Administration Tool aren't being recognized. The error message it gives me is a simple "log in or password is incorrect" - there's nothing about not being able to access the database or anything like that.
Does anyone know where I should look for the source of this problem, or has anyone else had this problem before?
Potentially releveant additional information:
When I first published the project, I got an error in my web.config that said "ApplicationServices" was already defined, preventing me from accessing any page on the site. I "fixed" this in a manner that would be called "hacky" only if someone was trying to be polite - I added "<remove name="ApplicationServices" />" right above it, so that portion of the web.config looks like this:
<remove name="ApplicationServices" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Any ideas?

Roles and Users are partitioned by ApplicationName. Check the aspnet_Applications table and compare that to what you see in aspnet_Roles and aspnet_Users.
This post by Scott Guthrie explains what is probably happening, and how to configure the ApplicationName on your providers.

Related

IIS 10 giving 401.3 access denied for PUT, DELETE, or PATCH for specific path

I'm working on a REST API, and doing test and prototype work on Windows 10 with its native IIS install. The API is written in C#. I've created a class that derives from IHttpHandler, and derive from that to implement classes for my API's nouns. (This allows me to commonalize logging, config, auditing, etc, in my base noun class). To implement verbs, the derived classes override the base class' functions for GET, POST, etc.
Anyway, one of the nouns I have is for access to the application's log. The path for this is /log. In it I've implemented GET, to read the log, and DELETE, to clear the log. GET works fine, however, DELETE gives me a 401.3 from IIS. I also get the same 401.3 if I try PUT or PATCH. PUT and PATCH are not implemented in the Logging class, so they should return a not implemented message. I do get the not implemented message if I try POST (which is not implemented in exactly the same way that PUT and PATCH are not implemented).
As part of trying to narrow down this behavior, I checked whether there were specific verbs being blocked by request filtering (there weren't). I checked whether Process Monitor was catching file system access denials at the underlying path (it wasn't... things never got that far.) I then tried adding another handler mapping - exactly the same as the first, but with a different path name:
<handlers>
<add name="BLOBRepoLog" path="log" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
<add name="BLOBRepoLogSanityCheck" path="foo" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
</handlers>
Using Postman, if I call DELETE on /log, I get the 401.3. If I call DELETE on /foo, it works correctly. If I call PUT on /log I get the 401.3. If I call PUT on /foo, I get the correct not implemented message.
Anyone have an idea why IIS should be doing extra scrutiny on verbs called for the /log path?
Thanks,
Paul
I had a similar issue where Put and Delete weren't working, it turned out for me that Webdav was the issue. In my case I didn't really need it so I uninstalled it and everything worked.

Post csv content to Web Api

I have a c# console application which post .csv content to a web service. If I run my solution through VS, it runs perfectly fine but after deploying web service on IIS I keep getting Multiple Choice Status Code 300 error. Not sure how to resolve that. Any pointers would be appreciated.
Thanks
These are relatively simple but I cannot think of other possibilities based on your description.
One of my recent designs had a literal in the code that when I deployed it ended up using a different port which I had forgotten to change to a relative reference.
If not that then the other problem I had with it was because I used JSON to link to the web service. While it worked when viewing in VS when deployed my JSON reference was actually incorrect. specifically it had to do with code in my web.config file, which would be the app.config file for your console application. I had used the code
standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="false" crossDomainScriptAccessEnabled="true"
when I should have also added
defaultOutgoingResponseFormat="Json"
to make the code work

Method not allowed in REST PUT

I know this has already been asked. I am in a crisis here.
I cannot make a PUT method to work. Just REST services. iis 7 windows 7 64 bits.
I get Method not allowed, and not a single hint. I am using a .svc file.
Please help!
Thanks
There could be many reasons why this is happening, I would recommend that you add the below to your web.config (just before the is closed), so that you can get some diagnostics information on what your WCF webservice is doing :
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\webservicelog.svclog" />
</listeners>
</source>
</sources>
Also, are you placing PUT in the method operation contract like below :
[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "DoWork")]
I have been downvoted, but if you check around, many people has been troubled by this.
So, things I learned:
ENABLE Trace Failed Requests!!! I was relunctant, and I should have done it before. Might have saved a full day and night, because I am the kind of guy that get obsessive with technical problems.
PUT methods can not be tested via url in a browser!!!!
I finally solved it by uninstalling WebDAV, thanks to Failed Trace!! I had already tried that, but I was sometimes checking with Chrome Rest Extension, and sometimes via URL in a Browser. Apparently, when I firt tried WebDAV uninstall, I never checked with Chrome Rest...
I know, I know, a was until yerterday a complete newbie. Now I am just a newbie.
I ended up writing my own code to consume the services to have full control.
For you guys having the same problem, please enable tracing failed request. Then, in the XML output, look for:
405
Close to that you will found the bastard causing it. In my case, it was webDAV.
Rememeber to use a tool that actually sends a real PUT verb, like rest Chrome Extension, or your own app. NOT URL in a Web Browser.
Regards

EF Code First not working on deploy hosting

I've an application using MVC and Code First for persistence.
Everything works fine in my development, but when I'm uploading to server, it doesnt work.
In any place i try to create a database, but it keeps me returning the following error: CREATE DATABASE permission denied in database 'master'.
The only thing that i do is override the OnModelCreating method just to map my app.
Anyone has this error?
Thanks
For a tutorial series that shows how to publish your Code First database and prevent Code First from trying to re-create the database in production, see
http://www.asp.net/mvc/tutorials/deployment-to-a-hosting-provider
The third tutorial in the series shows how to set up the Web.config file. The second shows how to deploy if you are using SQL Server Compact, the tenth shows how to deploy to full SQL Server.
You'll need to publish your database out to your hosting provider. Visual Studio has an easy way of doing this. In the server explorer tab, you can navigate to your database, right click and choose publish to provider. By doing this, you will not only export the scheme of your database, but you can also export out all data, stored procs, views etc.
You will need to adjust your code so that you are no longer trying to create a database on code run. Typically this approach is used for development, and you are no longer in development if you're moving to a hosting company. The changes may be in your global.asax, the dbcontext of your solution and any other place where you modified it to create the scheme for the database.
Hope this helps you some, and good luck on your project.

How to configure MVC config file for to have no caching

I am trying to figure out how to configure a ASP.NET MVC2 config file to have absolutely no caching. My current config file has this xml node...
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ZeroCacheProfile" duration="0" varyByParam="*" location="None" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
That would indicate to me, that no caching is going on with with this application. Am I missing something? Will continue to browse the internet searching for the most succinct answer. Thank you.
Defining a cache profile in web.config per se doesn't do anything useful other than defining a cache profile. There must be something using this cache profile otherwise it stays a simple definition. So that's half of the job.
The second half is to decorate all your controllers or actions that you would like to disable caching for with the [OutputCache] attribute:
[OutputCache(CacheProfile = "ZeroCacheProfile")]
or if you want to do this for all controllers of your site define a base controller that all your controllers derive from and then decorate this base controller with the aforementioned attribute.