IIS 7.5 Authorization Rules not working as expected - c#

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.

Related

Response.Redirect() Works in Visual Studio but not IIS

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");

Error Publishing to Azure 2.7 in VS 2015

I'm trying to do an Azure deployment with two web roles in it. I'm getting the following error after it builds and at the very beginning of the deployment.
Error CloudServices41 : The entrypoint ODataHQ.Query.dll is not a valid assembly. Please provide a relative path to the binary that implements the entrypoint. ODataHQ.Query.Azure C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.7\Microsoft.WindowsAzure.targets 1057
This error is happening on a co-workers machine as well. We just recently upgraded to Azure 2.7 inside of Visual Studio 2015 Enterprise and this is the first deployment we've attempted.
Can't find anything about it on the Internet, any thoughts?
Ok, I figured out the issue. I had added another worker role to my Azure deployment project, then I wanted to remove that worker role and add a web role in its place, but keep all the settings. So I manually renamed the worker role to the name of the web role in the ServiceDefinition.csdef, but I didn't change the tag to be a web role.
<WorkerRole name="MyProjectName" vmsize="Small">
Should have been changed back to
<WebRole name="MyProjectName" vmsize="Small">

visual studio 2012 debug for asp.net not working using IIS7

I can´t run visual studio 2012 debug for asp net using IIS7.
I have already tried the following
ASP NET Settings in IIS
.NET Compilation: Changed Default Language to c#
IIS Settings
ASP:
Changed script Language to c# (manually)
Enable Client-side debugging: true
Enable Server-side debugging: true
Script
- Language: c#
Also I am using Asp Net v4.0 app pool
Is there any other settings I can change to try make it work?
EDIT:
My user is part of Debbuger Users
The error is the following:
Unable to start debbuging on the web server. The web server is not configured correctly. See help for common configuration erros.
EDIT 2:
This is the log
Software: Microsoft Internet Information Services 7.5
Version: 1.0
Date: 2012-12-18 11:29:55
Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2012-12-18 11:29:55 ::1 DEBUG /tgpwebged/debugattach.aspx - 443 - ::1 - 403 7 5 43
EDIT 3:
I have manually configured the compilation element in web.config. This is the actuall config:
<compilation batch="true" debug="true" defaultLanguage="C#" explicit="false"
maxBatchGeneratedFileSize="10000" maxBatchSize="10000"
numRecompilesBeforeAppRestart="100" strict="false"
tempDirectory="C:\Windows\Temp" urlLinePragmas="false"> </compilation>
Also just for test purpose changed the user ASP NET V4 app pool runs under to my account. Not the SYSTEM.. my personal account. No success yet.
I have had this issue before (although not with VS2012) and the following things have worked:
Ensure IIS is configured for Integrated Windows Authentication.
Make sure HTTP Keep Alives are enabled.
Make sure http://localhost is in your trusted sites in your web browser.
Can you attach your debugger to the w3wp process and debug that way ?
Here is an article: Attatch debugger to an IIS process
Try to run the following in the command line:
cd %windir%\Microsoft.NET\Framework\v4.0.30319
aspnet_regiis.exe -i
Typically you have to run Visual Studio as a local administrator for debugging to work.
I'm running into something similar on VS2010 with a site hosted on IIS7.5. I'm trying to hit F5 and get my website to start up an automatically attach a debugger.
I think the key is this line in your log:
2012-12-18 11:29:55 ::1 DEBUG /tgpwebged/debugattach.aspx - 443 - ::1 - 403 7 5 43
As far as I know, debugattach.aspx is some sort of hook that VS will try to invoke before it can actually start up and run your app. Details are a bit sketchy on the interwebs about what this thing actually is, however it does seem that if you don't get a 200 (success) VS won't be able to automatically attach. Basically it fails on step 1. In your log, you have a 403 (authorization error) for this request, I have a 404 (not found) in my log.
In your specific case, you might have something in your IIS config that's blocking the DEBUG verb. It's a common security practice to block uncommon verbs or anything other than POST and GET. In my case, it's probably similar - the aspx extension is probably being filtered out. It could also be the default authentication settings for the app in question.
Update: I did solve this on my end, and two separate things were wrong. First, I was using UrlScan.dll for security and it was blocking the DEBUG verb. Also, I was using a UrlRewrite rule to go from HTTP to HTTPS and the 302 redirect it generated also blocked this VS request. I was able to find both issues using the IIS Failed Request Tracing feature. The logs from that tool give some insight on what various modules and handlers in the pipeline are doing.
Hopefully this helps!
I've just had the same situation. I have solved it and here's how I did it:
Check if it's the right .NET Framework edition on the IIS.
Check your application pool's pipeline mode, for some apps - it only allows Classic mode.
Check if there's any other application under the application which you want to debug.

Error on publishing: System.DirectoryServices.DirectoryServicesCOMException

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

connectionString encryption

I'm trying to encrypt the connection strings in my web.config. I'm following the instructions from Walkthrough: Creating and Exporting an RSA Key Container. However, when I get to the part with the command:
aspnet_regiis -pe "connectionStrings" -app "/MyApplication" -prov "MyProvider"
it keeps complaining:
"The configuration for the virtual path '/MyApplication' and site 'Default Web Site' cannot be opened
Failed to map the path '/myapplication'
Failed!
I'm fairly sure I've followed the instructions correctly. I created the project named 'MyApplication' directly in the 'C:' root.
Any ideas? Perhaps I should be following a different set of instructions?
Thanks for your answers. Turned out I needed to run the command prompt as "Administrator"
Did you add the MyApplication folder as a virtual directory in IIS under the default web site? That seems to be what it's looking for, not a folder path...
According to this MSDN post, you can use -site to define the site to target. An excerpt from that site:
Use the –app option to identify the application for which the
Web.config file will be encrypted and the -site option to identify
which Web site the application is a part of. The Web site is
identified using the site number from the Internet Information
Services (IIS) metabase. You can retrieve the site number from the
INSTANCE_META_PATH server variable in the ServerVariables collection.
For example, when IIS is installed, a Web site named "Default Web
Site" is created as site 1. In pages served from that site, the
INSTANCE_META_PATH server variable returns "/LM/W3SVC/1". If you do
not specify a -site option, site 1 is used.
/MyApplication is a virtual path and the message seems to indicate that path is not available i.e. there is no http://localhost/MyApplication. Did you forget to create virtual directory for your app in IIS?

Categories

Resources