I'm using the AD authentication in my asp.net MVC solution. It's working in a local server, but when I publish it I get the error: "System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.". Does anybody know what I have to do?
Verify if you are publishing the dlls: System.DirectoryServices.dll and System.DirectoryServices.AccountManagement.dll.
Go to References in your web project, find both references, press f4 (properties tab), and set "Copy Local" to "True".
-- Added later
After, verify in your iis, if the setting "Asp.Net Impersonation" is enable. (Click in your web app in iis, and after, in Authorization icon)
I found this part of code and its works now:
using (HostingEnvironment.Impersonate()) {
// This code runs as the application pool user
DirectorySearcher searcher ...
}
http://sanjaymungar.blogspot.com/2010_07_01_archive.html
or
http://sharepoint-tweaking.blogspot.com/2007/12/impersonation-in-aspnet-causes.html
Related
I decided to publish the ASP.NET MVC project to test it locally using IIS Manager. Therefore, after opening the necessary windows features, I created a new folder in the C:\inetpub\ directory on IIS Manager:
In the Visual Studio IDE I right clicked on the solution and clicked "Publish..." and specified that the target was "Folder":
When I clicked the Next button, I specified in the next window that the "Target" location was the C.\inetpub\TechnologyArticle directory. Then when I clicked the "Publish..." in the Visual Studio IDE, I encountered an error that I did not receive in Debug mode:
System.AggregateException: One or more errors occurred.
---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed.
---> (Inner Exception #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed.
---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed.
How can I solve this problem? Is the reason why I got this error in Release mode, which I did not receive in Debug mode, due to programming?
This error is not due to programming. The reason for this error is trying to publish the website in the C:\inetpub\ directory, which is made visible and/or created by a service that you have activated by "Turn Windows features on or off" to publish the ASP.NET website locally. The user has no right to modify the C:\inetpub\ directory. Therefore, the current user's right to modify the C:\inetpub\ directory must be declared manually in the Windows 10 operating system.
When the ASP.NET website is published, the project outputs (such as *.dll files, style files, scripts, Views) compiled in Release mode will be extracted to the target directory, so the user must have the right to write to the C:\inetpub directory.
To resolve this issue, follow the steps below:
Open the properties of the C:\inetpub folder (With the folder selected, use the ALT + ENTER shortcut).
Switch to the Security tab and click the Edit button.
Define "Full Control" right for current user and confirm settings by clicking OK button.
You repeat the publish procedure to publish your website.
I have created a Windows Service using ASP.Net Core 3.x and C#. I started with the new Windows Service template when I built the project. When I run it from my development environment or from a console window it runs fine. When I install it as a Windows Service and attempt to start the service I get an
"Error 5: Access is denied." error.
I tried numerous things which I will outline below to eliminate the error but nothing seemed to work so I downloaded the sample app provided by Microsoft, at sample
Same result...when I run the sample app from within Visual Studio it runs fine, when running as a service I get the Access Denied error.
I am running all of this on my local machine, which I am an admin on.
I originally tried to run it using the default Local System account; got the Access Denied error.
I changed the Log On As to my domain account, the same one I use to log into my local machine which is an admin on this machine; got the same Access Denied error.
My account has the privilege set to run as a service.
The Event Viewer just shows the one message which says "Access Denied", no other messages are created.
I believe the Access Denied error is occurring before the C# code is even executed. What makes me believe this is that I added one line to the very top of the Program.Main.... File.WriteAllText("C:\\temp\\ws.log", $"Test of Worker Service # {DateTime.Now}. Content Root Path: {AppContext.BaseDirectory}");. My account has full access to the temp folder. This file gets created when I run the app from Visual Studio but it does not get created when I run the app as a service.
I have read numerous web sites, include this one and this one. No luck, everything I tried from these sites still produce the Access Denied error.
I have run out of ideas and am hoping someone here can provide me the answer. Thanks!
I found the solution and believe me I feel really stupid!!!
When I installed it as a service I only put the path in "binPath".
sc create WindowsService1 binPath="C:\temp".
Once I actually added the executable to the binPath parameter everything worked.
Changed it to sc create WindowsService1 binPath="C:\temp\WindowsService.exe" and it worked.
I know it is an Id10t error but Microsoft should really provide better messaging for the "sc" command. A message like "Cannot find file specified in the binPath parameter" would have been really helpful. Would have saved me about 6 hours of work.
Thanks everyone for reviewing and replying to this question.
I'm trying to upload a basic web application from visual studio on Windows 7 to an IIS environment on Windows Server 2007.
Though launching it from IIS displays the Login page, trying to navigate past it to the main menu returns this error:
Server Error in Application "PARKING/PARKING ASSIGNMENTS WEB"Internet Information Services 7.0
Error Summary
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Detailed Error Information
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://localhost:81/Parking Assignments Web/Home
Physical Path C:\ParkingAssignmentsWeb\Home
Logon Method Anonymous
Logon User Anonymous
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
•Create the content on the Web server.
•Review the browser URL.
•Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
Links and More InformationThis error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
View more information »
This is the code I used for navigation:
Response.Redirect("Home.aspx");
Why would this navigation work on Visual Studio but not on IIS?
UPDATE: I tried the variations of the Redirect command you guys showed me but all of them gave a 404 error, which leads me to believe that the problem isn't with the command but with something else. Any idea what?
It treats Home.aspx as a relative path.
Use it like:
Response.Redirect("/Home.aspx");
when you deploy to IIS a different web server is being used. Visual studio uses a web server with limited options and in most cases but not all an application should run without changes when deployed to IIS on windows server.
Things to check
Verify that the folder structure on your workstation looks the same as the folder structure deployed to the server.
check permissions on the folders accessed by IIS on the web server
Response.Redirect("Home.aspx"); assumes that the file is in the same directory as the page that is invoking the transfer
add a more complete path either ("/home.aspx") or ("/folder/home.aspx") where folder is the actual folder name that contains the .aspx file
Please try:
Response.Redirect("~/Parking Assignments Web/Home.aspx");
or
Response.Redirect("~/Parking Assignments Web/Home");
I have a basic Visual Studio project, 2 folders in a site, one folder called 'pub' which should be publicly available, and one called 'auth' which requires you to sign in to view the contents. I have 2 location rules in the web.config that manage that.
I am also using a basic auth module (http://www.asp.net/web-api/overview/security/basic-authentication) which is added to modules in IIS and registered
In VS when I debug using IISExpress, everything works as expected, 'pub' let's me in no problem, and auth prompts me for credentials using 'basic' auth. But when I publish (through VS, delete all files prior to update) the site to IIS 7.5 every folder requires authentication, which is wrong.
Now if it is the BasicAuthModule that is causing the issue, then how do I get prompted for credentials using basic auth in IISExpress, but if it isn't the module then what is different between the IISExpress debug install and my servers?
There isn't really a lot of code to show, but here is my web.config with the code that we are using:
-system.webServer-
-modules-
-add name="BasicAuthHttpModule" type="WebHostBasicAuth.BasicAuthHttpModule" -
-/modules-
-/system.webServer-
-system.web-
-httpRuntime targetFramework="4.5" -
-authentication mode="Windows" -
-/system.web-
-location path="~/services/public"-
-system.web-
-authorization-
-allow users="*"-
-/authorization-
-/system.web-
-/location-
-location path="~/services/auth"-
-system.web-
-authorization-
-deny users="?"-
-/authorization-
-/system.web-
-/location-
Obvious answer, redesigned the site to have virtual directories for the auth and pub and changed the auth methods for each one.
I just though there should be a better way.
I get the following error when trying to start the ASP.NET State Service:
Windows could not start the ASP.NET State Service service on Local Computer.
Error 2: The system cannot find the file specified.
Everything I found on google told me to go to the %windir%\Microsoft.NET\Framework\v1.1.4322 folder at the command prompt, and then type the following command: aspnet_regiis.exe -ir
which I did and didn't solve the problem. The path to the executable in my case is 2.0: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_state.exe.
So I tried the same comand on the v2 folder and I get the error:
"An attempt was made to load a program with an incorrect format".
thanks in advace for any help
As stated here, it's trying to load the 32-bit version while you need the 64-bit. If this is applicable, open RegEdit (own risk and so on) and change HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\ImagePath
from %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_state.exe to %SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\aspnet_state.exe.
You not need reinstall this service.
Just find in services "ASP.NET State Server" and start it.
Also you can set up to start this service automaticaly in preferences.