I have a Silverlight application (using MVC) and when i'm building in visual studio, using Visual Studio Development center, there's no problem, the HttpContext.Current.User.Identity.Name has a Value
But when i'm using the same project with IIS 7.5 (i'm using Windows 7), HttpContext.Current.User.Identity.Name stays empty
Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what's wrong in IIS?
I struggled with this problem the past few days.
I suggest reading Scott Guthrie's blog post Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application
For me the problem was that although I had Windows Authentication enabled in IIS and I had <authentication mode="Windows" /> in the <system.web> section of web.config, I was not preventing anonymous access. This last part was the key. You need to prevent anonymous access to ensure that the browser sends the credentials.
You can either configure IIS in Control Panel so that your site (or machine) uses Windows authentication and denies anonymous access or you can add the following to your web.config in the system.web section:
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
These might resolve the issue(It did for me). In IIS Express change the project property values, "Anonymous Authentication" and "Windows Authentication". To do this, when project is selected, press F4 and then change these properties.
In case you are deploying it on IIS locally, make sure local machines "Windows Authentication" feature is enabled and "Anonymous Authentication" is disabled.
Refer to
https://grekai.wordpress.com/2011/03/31/httpcontext-current-user-identity-name-is-empty/
In addition to "answered Mar 28 '11 at 12:27Bryan Bedard"
In case that the solution doesn't work, you have to enable Windows Authentication in iss manager.
How to do that:
1.To start IIS Manager from the Run dialog box:
On the Start menu, click All Programs, click Accessories, and then click Run.
In the Open box, type inetmgr and then click OK.
2.In the Connections pane, expand the server name, expand Sites, and go to the level in the hierarchy pane that you want to configure, and then click the Web site or Web application.
3. Scroll to the IIS section in the Home pane, and then double-click Authentication.
4.In the Authentication pane, select Anonymous Authentication, and then click Disable.
In the Authentication pane, select Windows Authentication, and then click Enable.
Reference
Disabling all other options in authentication tab of iis except windows authentication resolved my issue.
Please check..
Steps:
Open iis in your machine
Select your application from the application pool
Click on authentication option
Disable all other option except windows authentication (Anonimous authentication should be disabled)
Please check this and let me know the feedback. It worked for me. hope it will work for you also..
I also had this problem recently. Working with a new client, trying to get a an old web forms app running from Visual Studio, with IISExpress using Windows Authentication.
For me, the web.config was correctly configured
However, the IISExpress.config settings file had:
<windowsAuthentication enabled="false">
The user account the developer was logged in was very new, so unlikely it had been edited.
Simple fix it turned out, change this to enabled=true and it all ran as it should then.
Also, especially if you are a developer, make sure that you are in fact connecting to the IIS server and not to the IIS Express that comes with Visual Studio. If you are debugging a project, it's just as easy if not easier sometimes to think you are connected to IIS when you in fact aren't.
Even if you've enabled Windows Authentication and disabled Anonymous Authentication on IIS, this won't make any difference to your Visual Studio simulation.
The browser will only detect your username if the IIS server is on the same domain and the security settings within your group policy allow it.
Otherwise you will have to provide it with credentials, but if it is not on the same domain, it will not be able to authenticate you.
Apart from all obvious reasons mentioned earlier, there might be another one: you didn't put an Authorize attribute on top of your controller, like that:
[Authorize(Roles = "myRole")]
[EnableCors(origins: "http://localhost:8080", headers: "*", methods: "*", SupportsCredentials = true)]
public class MyController : ApiController
At least that's what worked for me.
As #PaulTheCyclist says, If using IISExpress anonymous authentication is enabled by default, windows authentication is disabled.
This can be changed in what I'm sure used to be called PropertyPages (NOT right-click -> properties). Select the web project
Try enabling basic authentication and disabling the other authentications in IIS, then try launching the application. The application will ask for windows credentials. Enter the same and the app should be able to get the name under HttpContext.Current.User.Identity.Name.
I was facing this issue when authentication mode was not set while creating the project.
So It worked when created a new project with authentication set to windows mode in the initial settings.
Related
I initially installed the Microsoft Visual Studio Express 2013 for Web on my desktop. My desktop runs Windows 8.1 with internet explorer 11. It ran fine until the license expired after the first 30 days. I tried to sign in to renew the license, however after clicking the 'sign in' button I get an error dialog. The dialog states 'Browser is security restricted or javaScript is disabled. I have no other option but to close and exit Visual Studio.
I went to the online forums for Microsoft. There were discussions and suggestions on how to fix the error. I tried lowering the settings for the security tab in internet explorer. I have validated the option for scripting is enabled. I have also added https://*.visualstudio.com to the trusted sites tab. Other users on the forum have tried the same suggestions and have not succeeded in signing into the visual studio application.
I had exactly the same problem, here is what I did:
a) Go in IE, click on settings wheel then Internet Options and Security tab.
b) Click on Custom level button (make sure you select Internet zone).
c) In Security Settings window, under Scripting I set Enabled for Active scripting.
After that Sign In should work. Even though Chrome is default browser, it seems that VS uses IE for sign in process.
Hope this helps!
There is another issue people are running into that is a bug with the login dialog. The login dialog is using a Web Browser control to login the user. By default it loads up "about:blank" as the URI. It then proceeds to try to execute some JavaScript (just ";") to verify it has permissions to do so. On some machines this is problematic because "about:blank" has been mapped to zone 0, or the Local Machine zone. When the JavaScript is executed MSHTML will check the zone of the URI and then the policy for executing scripts. By default the Local Machine zone is locked down, and all script executions result in a Query policy. What this means is if you're running in immersion mode (aka in Internet Explorer) you will get a message box asking if you want to execute the script. However, the Web Browser control used by VS 2013's "Sign In" dialog doesn't run MSHTML code in immersion mode, so the Query policy effectively equates to a Disallow policy. The bug here is someone in VS assumed "about:blank" resolves to the Internet zone, and when it resolves to the Local Computer zone you get this behavior.
The workaround is to remove "about:blank" zone mapping. Point regedit to this key:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains]
Remove the "blank" key.
Alternatively you can change the Local Machine Lockdown policy for executing scripts. The reg key for that is:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lockdown_Zones\0]
Set the "1400" DWORD value to 0.
There are many sites you need to list in your Trusted Sites. Following the trace of what the stupid, stupid login script does:
https://.visualstudio.com
https://app.vssps.visualstudio.com
https://.accesscontrol.windows.net
https://auth.gfx.ms
https://login.live.com
Only then was I able to log on to my FREE software.
Hi this is Albert from Microsoft. Just want to let you all know that this issue has been fixed in the upcoming Update 2 for Visual Studio 2013. Thanks for your patience while we figured this one out :)
Same problem "Browser is security restricted or JavaScript is disabled" here but the solution from #jic didn't work for me..
If you can and it is convenient for you this is a solution which worked for me:
I have created a new user/profile on my PC and for this user it was just working fine.
Before this action I have tried to make an user account which had this problem as:
Power user - didn't work
Administrator - didn't work as well
So the last solution in my case was a brand new user on the PC..
Here's what worked for me.
Open Control Panel, Internet Options.
First, I clicked the Security tab and turned security the security for the Internet zone to its minimum.
Next, click the Privacy tab, then click Advanced. Choose "Accept" for both types of cookies.
Of course you can change these all back after extending your VS trial.
you must change secure settings of iexplore for admin account. If logon by other account, you must start iexplore under admin account or logon under admin account, because you will get license after admin account.
Click on Start --> Run --> type cmd and click on OK.
Command Prompt will be opened. Then enter this command.
ipconfig /flushdns
and press Enter.
Now try to access https://app.vssps.visualstudio.com/Profile/View
It worked for me...
As I can not add a comment yet to the answer of CBGraham, I've to add this note over here:
The solution described from CBGraham worked for me (Thanks Graham). I had to add an additional link:
https://account.live.com
Then I opened the IE and tried to login to a Microsoft site. I left the IE window open and just clicked once again on the VS to login. Then it worked for me. Even with strong restrictions on the IE settings. While I'm surprised why someone should set down his security settings, just to register VS.
I am working on a website which authenticates with Facebook, so that the user can sign in through his/her Facebook profile. I've seen similar questions like this one, but none that covers exactly my issue.
To test this Facebook authentication locally, I figured that some hacks were needed. You see, Facebook only allows redirects to certain domains after the authentication process. For these domains, localhost is not an option.
So I decided to do some research. I ended up changing my hosts file to point the domain local.fablelane.com to 127.0.0.1. However, now it complains when I try to change the virtual directory in Visual Studio 2012.
First, I see this dialog after changing it.
I then click Yes and end up with this dialog here.
What do you suggest I try? How can I change my virtual directory? It is important that I find a way to do this either programmatically, through changing a file somewhere, or through the commandline. The reason for this is that I intend to make an automatic setup program that does this for me in the future.
You will need to uncheck Use IIS Express and also add your new name local.fablelane.com as a binding to IIS, so that when VS tries to open the site URL, the host-header matches the site.
Also, is there any reason you need a specific port, rather than the default? It should be fine with 80.
You haven't said which version of IIS you're using, but on 8, open IIS Admin, expand your machine-name, expand Sites, right-click on local.fablelane.com (or however you've named it), and select Edit bindings and add local.fablelane.com.
Try uncheck the option "Use IIS Express".
Check if your website port number in IIS has been changed.If its changed edit bindings and change port number to 80
In addition to the above, click on the override application root URL and paste the host name address which you have given in the Project Url.
It worked for me.
I am attempting to run an application in IIS8 that has the following in the config:
<modules runAllManagedModulesForAllRequests="true" />
IIS8 is giving me an error that says...
This configuration section cannot be used at this path. This happens
when the section is locked at a parent level. Locking is either by
default (overrideModeDefault="Deny"), or set explicitly by a location
tag with overrideMode="Deny" or the legacy allowOverride="false".
I'm guessing by the error and a quick SO search that there is some higher level security setting that's preventing that line from being allowed. Any ideas?
I've solved the same problem by installing the window features "Internet Information Service/World Wide Web Service/Application Development/ASP.NET x.x" in the Control Panel of Windows8. If you want to setting on Windows Server 2012, the following link gives you hint.
http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-using-aspnet-35-and-aspnet-45
hope that it works out.
For those of you running Windows Server 2012 the Application Development features are found at
[] Server Roles
[] Web Server IIS
[] Web Server
[] Application Development
[] ASP.NET x.x
When you select the .NET version it will ask if you want to add Extensions and other features. I just said yes, but you may be able to get away without installing those.
its hard to give a specific answer here, but the basics of it are that you need to look at the machine.config for the box you're running on. find the system.webServer node and look for the 3 tags/attributes its referencing in the error. chances are you'll find something that is marked as not overridable (allowOverride="false"), but i've not messed with windows 8/server 2012 yet, so i don't know what the machine.config looks like.
You can unlock the section via the IIS UI per https://serverfault.com/a/516921/137255
Open IIS Manager
Click the server name in the tree on the left
Right hand pane, Management section, double click Configuration Editor
At the top, choose the relevant section based on the offending item's XPath; i.e. system.webServer/modules for this example.
Right hand pane, click Unlock Section
I have recently tried to install TargetProcess http://www.targetprocess.com/ on my windows machine, which involves installing IIS and an instance of SQLEXPRESS.
I have no previous with IIS so most to the concepts where new to me. After much head scratching and tinkering I managed to get TargetProcess to install. However when I try to run it in a browser I get teh following error
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.
The page I am trying to run is .aspx and I have run a page.aspx to verify that .aspx are not being restricted as suggested by the error message.
Anyone got any ideas as to what else it could be?
Kevin,
In the IIS management console, please open ISAPI and CGI Restrictions feature fro your hosting server. ASP.NET v2.0 and v4.0 restrictions are set separately. TargetProcess application is using .NET v4.0 since 2.22.9 build, so please check, that MS .NET framework v4.0 is installed and ASP.NET v4.0 is allowed. Also on the Handler Mappings section for TP web site PageHandlerFactory-ISAPI-4.0 should be enabled.
Please contact us via http://messenger.providesupport.com/messenger/targetprocess.html if you need any assistance.
Regards, Alex - TargetPro
To solve:
1.- Go to IIS manager and clic on your server name (when tooltip says localhosts)
2.- double clic on ASAPI and CGI restriction
3.- right clic to change all items to ALLOWED
The "ISAPI and CGI Restrictions" option was not there on my machine. I had to go back into the "Turn windows features on and off", then the "Internet Information Services" / "World Wide Web Services" / "Application Development Features" and then ticked the "CGI" option. Once I did this, the "ISAPI and CGI Restrictions" option appeared after I closed and re-opened IIS. Just mentioning it here in case anyone else has the same problem.
This seems like a simple question, but I have googled it and cannot find an answer.
When I hit F5 in a Windows Azure solution in Visual Studio 2010 (the Azure project is the startup project), after a long time (a seperate issue) one of my web roles is running as expected.
However, I have 2 web roles in my solution, and I cant work out how to set a particular role as my 'default' role when running the solution in the debugger (as described above).
At the moment Im making a note of the tcp port assigned to each role in config, then changing the url in my browser for the web role I want.
Surely I should be able to set the default debugger web role in some property window somewhere - or am I missing something ??
Thanks
Dean
Right click the webrole(s) you do not want to start and click "properties" > "configuration" and uncheck "startup action" > "launch browser for" "HTTP Enpoint" [and "HTTPS Endpoint" if applicable] - leaving this/these options checked for the webrole you do want to start [development scenario].