System.UnauthorizedAccessException when accessing a custom database connection DLL - asp.net

I'm having issues with vs2010 debugger. I have an application that uses a forms log-in then uses a custom connection .dll to connect to the database. The web application seems to run as expected when accessing it straight through IE, but when I use the debugger it throws a System.UnauthorizedAccessException trying to access the connection DLL located in the GAC. It seems to be a permissions problem for the user that the debugger uses. This is a little outside of my scope of knowledge.
Here is my iis7 settings
<applicationPools>
<add name="DefaultAppPool" autoStart="true" managedPipelineMode="Classic" startMode="OnDemand">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" pingResponseTime="00:05:00" />
</add>
Application Set up on server
<application path="##AppName##" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="##APP Path##" />
</application>

Related

MVC4: Preload application without having access to IIS

I want to have my MVC application to warm up the application after it is being restarted, so the next initial loading will cost almost no time.
The problem is that I do not have the access to the server computer IIS.
I have searched of how to do it, and I found this:
<applicationPools>
<add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
</applicationPools>
But this code requires access to the server computer.
How can I do it only with my application and web.config?

VS 2013 / IIS Express - serve site from localhost:port/myapp instead of localhost:port

In prod my site (mvc5) is hosted on https://company.no/myApp/ where myApp is an Application on IIS.
In dev my site is hosted on IIS Express on http://localhost:54307/
As this causes some truble with server relative paths I would like to also do my debugging on http://localhost:54307/myApp.
This is what I've tried:
Setting project url in property pages to http://localhost:54307/myApp and clicking Create Virtual directory
Tried the override application root with or without the myApp url.
Tried modify the applicationhost.config. Currently my setting looks like this:
<site name="MyApp.Web-Site" id="38">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\OP\MyApp\Main\src\MyApp.Web" />
</application>
<application path="/MyApp" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\OP\MyApp\Main\src\MyApp.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54307:localhost" />
<binding protocol="https" bindingInformation="*:44307:localhost" />
</bindings>
</site>
When I try to open page from the myApp folder I get the follownig error:
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x800700b7
Config Error Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'WSFederationAuthenticationModule'
Config File \\?\C:\Projects\OP\MyApp\Main\src\MyApp.Web\web.config
Requested URL http://localhost:54307/MyApp
Physical Path C:\Projects\OP\MyApp\Main\src\MyApp.Web
That indicates web.config loaded twice. Any idea what I'm doing wrong?
Thanks for any help
Larsi
I hear you with IIS Express causing problems with server relative paths. You can set this up with a couple steps that don't include manually editing your applicationhost.config. I try to avoid editing the applicationhost.config manually, it seems to cause more problems than it solves. I would remove the website from your local IIS to clear out any of that stuff and then do the steps below:
right-click on your web project and select properties.
Click on the "Web" menu
change the dropdown to Local IIS and enter the URL you would like the app to resolve to then click create virtual directory, save the file and build.
You can still debug without the port number, the debugger will just attach to this new website in your local IIS instance as long as you have a debugger option checked on the web tab.
open your local IIS and make any other configurations that are required for your app to run (Authentication, Application Pools, etc.).
open your browser and navigate to http://localhost/YourAppName
since this is a website as far as your local iis is concerned, you can hit it anytime in a browser without needed Visual Studio running.

IIS Application Initialization not Firing into ASP.NET Application

Running on Windows 8, I have enabled the Application Initialization feature of IIS from the Windows Features install options for IIS.
I'm attempting to get an ASP.NET Web app to start up immediately and fire into Application_Start when the Application Pool is restarted. I've followed the instructions from this tutorial, but after setting the values in the ApplicationHost.config, and web.config I see nothing is firing.
Here's what I've set (which seems to match what the article suggests):
<applicationPools>
<add name="MPress" autoStart="true"
enable32BitAppOnWin64="true"
startMode="AlwaysRunning">
<processModel identityType="LocalSystem" setProfileEnvironment="true" />
</applicationPools>
<sites>
<site>
<application path="/MPress.Workflow.WebQueueMessageManager"
applicationPool="MPress" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="C:\Projects2010\Clients\MPress\MarvelPress.Workflow.WebQueueMessageManager" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
</sites>
And then in the local web.config I have:
<system.webServer>
<applicationInitialization remapManagedRequestsTo="Startup.htm"
skipManagedModules="true"
doAppInitAfterRestart="true">
<add initializationPage="default.aspx" />
</applicationInitialization>
</system.webServer>
Other than the doAppInitAfterRestart flag this matches the settings in the above article exactly except pointing at my virtual app and application pool.
It appears that the Application Pool auto load works - if I stop and restart IIS w3wp I see the application pool show in the task list. But using Process Explorer I can see that the EXE hasn't loaded .NET just sitting there. No .NET Runtime dlls are loaded, so it appears that no request has fired.
What really sucks is that there's no real documentation of section and expected values required for each setting. The doAppInitAfterRestart flag is documented nowhere that I could find. I've also left that out with the same results. I'm also not 100% what the syntax for the URL is. The MSDN article points at "/default.aspx" and I tried that too to no avail.
I also turned on Failed Request Tracing in IIS to see if maybe the fake request fails somehow, but nothing shows up in there. It simply looks like Site Level load is not firing when the application pool restarted.
All of the settings mentioned here are also available through the IIS Admin UI in Windows 8 and everything certainly looks correct.
I'm out of ideas on what else to check or what I might be missing. Any ideas appreciated.
After some more spelunking it turns out that although I had installed the Application Initialization feature using the Windows 8 features, the actual module was not added to the globalModules list.
The following was missing and once added everything started working just fine:
<globalModules>
<add name="ApplicationInitializationModule" image="%windir%\System32\inetsrv\warmup.dll" />
</globalModules>
I faced similar issue but after doing a bit of comparison I found that you need to set Application Pool Managed Pipeline Mode to Integrated. It will not work with Classic Mode

Using ASP.Net Preloader in IIS 7.5 Express

Scenario
I am attempting to auto-start/keep-alive/preload information in my ASP.Net application. The instructions are plain and clear: ASP.Net + IIS 7.5 - Preloading & Auto Starting, but I am having problems with doing so in IIS 7.5 Express. I get a 500.19 error regarding some of the config elements. Below is context and question:
ApplicationHost.config
<!-- Inside the ApplicationPools element we tell the appropriate app pool
to auto start and always run. -->
<add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" startMode="AlwaysRunning" />
<!-- In the Sites element we first ensure our application is using the correct
app pool. Then we tell it to use the pools auto start functionality, and
point it towards a provider to use. -->
<site name="ED.Web" id="11">
<application path="/" applicationPool="Clr4IntegratedAppPool" serviceAutoStartEnabled="true" serviceAutoStartProvider="Preload-UserReconciliation">
<!-- everything is properly closed -->
<!-- Just before closing the Sites element we declare a provider; it identifies
the class within a particular assembly that should be used for preloading -->
<serviceautostartproviders>
<add name="Preload-UserReconciliation" type="ED.Web.ApplicationPreload, ED.Web" />
</serviceautostartproviders>
</sites>
Error 1
Error 500.19, Unrecognized element 'serviceautostartproviders'
239: <serviceautostartproviders>
240: <add name="Preload-UserReconciliation" type="ED.Web.ApplicationPreload, ED.Web" />
Error 2 [EDIT]
After shutting down IIS Express entirely, and launching the app from VS again, I get a Visual Studio popup: "Unable to launch the IIS Express Web server."
Question
How do I properly setup IIS Express 7.5 to start the pool, and preload the app using my ApplicationPreload : IProcessHostPreloadClient class?
Embarassing...
http://www.iis.net/download/ApplicationInitialization
I completely missed that this was an out-of-band module for IIS 7.5, not base functionality.
It is included in base functionality beginning with IIS 8.0.
The original post I found with this information on it, did not point that out, and when I used the link referenced in question, I completely breezed over the bright yellow box looking only at the code.

Child Application with 2.0 App Pool running under a Site with a 4.0 App Pool

Scenario
I have an IIS Site application built using ASP.Net 4.0, running with its own app v4.0 app pool. Hosted by this site is a child Application built using ASP.Net 2.0, with its own app pool.
<site name="Intranet" id="1" serverAutoStart="true">
<application path="/" applicationPool="Site-Intranet">
<virtualDirectory path="/" physicalPath="D:\sites\intranet" />
</application>
<application path="/ChildApp" applicationPool="App-ChildApp">
<virtualDirectory path="/" physicalPath="D:\apps\childapp" />
</application>
</site>
My first thought is that the 2.0 Application should run using a v2.0 app pool. visiting the URL when doing so causes a server error -- it does not recognize the "targetFramework" attribute in the parent Site's web.config compilation settings.
I understand why, and have found two solutions/workarounds, but I do not fully understand the implications of each one.
Fixes
1. Set Application's app pool as v4.0.
2. Leave the Application's app pool as v2.0, but change the parent Site's web.config to break inheritance on the <compilation> section:
<location path="." inheritInChildApplications="false">
<system.web>
<compilation targetFramework="4.0" debug="true" />
</system.web>
</location>
Question(s):
What's really going on with these fixes/solutions?
In scenario #1, is the 2.0 Application being compiled/run by the 4.0 CLR? Assuming so, is the CLR attempting to run it as a 2.0 app (i.e. backwards compatibility)? Or is it simply assuming it is a 4.0 web app (seems dangerous)?
In scenario #2, I know we have stopped the child app from seeing the targetFramework attribute, but is the 2.0 CLR truly compiling/running the application? If so, is this all that is needed to safely run an ASP.Net 2.0 application under an ASP.Net 4.0 site?
I have used scenario #2 many times and never had any problems. So yes this is all that is needed to safely run an ASP.Net 2.0 application under an ASP.Net 4.0 site.
Although no one can answer that your two applications will definitely work together this way. Probably best to do a full system test and if you do find any specific problems post a new question.

Resources