Several asp.net apps in single Azure App Service - asp.net

I got two working asp.net projects - API and site itself. I am trying to deploy it to one instance of Azure App service. But I got working configurations only if I deploy it to app's subfolder, and create non root virtual applications, e.g.:
But if I am trying to make root app for site:
I got problem with API project - it fails to work, cause it is trying to load Web.config from 'root' virtual application:
How could I made virtual app to load its own config file - not from the root app?

You can use inheritInChildApplications in your application(not api) web.config to stop inheritance.
Wrap system.web section with location element with inheritInChildApplications set to false
<location path="." inheritInChildApplications="false">
<system.web>
…
</system.web>
</location>
You can read more about it here

Related

Configure URL in IIS

I have an existing DNN site set up in IIS and I want to link to another ASP.NET application in a separate folder. I want to maintain the same domain URL as follows:
http://dnn9.dnndev.me/otherapplication
Can anyone point me in the right direction?
UPDATE
Currently, the main DNN site is set up as its own site in IIS (not under Default Web Site)., with its own App Pool. I tried adding a virtual directory to the main DNN site, pointing to the other application folder. It gives a 404. I added <location path="." inheritInChildApplications="false"> around the system.web section of the DNN site web.config. My main DNN site is set up as "dnn9.dnndev.me". I'm wondering if the "dnn9" subdomain on my local is causing an issue?
The other application is added as an application under Default Web Site in IIS, with its own App Pool.
I just created two test websites "Test1" and "Test2". I placed both of these under the "Default Web Site" node in IIS and added a virtual directory to Test1, pointing to Test 2 and it worked. So the main difference between this test scenario and my actual setup is that DNN is set up in IIS as a standalone app, not under the "Default Web Site" node in IIS.
How can I get this to work?
I was able to make the following scenario work.
DNN running in a website in IIS called "DNNDEV.ME" with the URL binding being set for DNNDEV.ME. Location of the DNN files c:\websites\dnndev.me
Created a new "APPLICATION" under the DNNDEV.ME site, using the same DNNDEV.ME application pool. I pointed that application's root to the folder c:\websites\newapp\
Modified the DNN web.config file to wrap <location path="." inheritInChildApplications="false"> around the system.webServer node
With that functioning I added a file called sample.aspx, with the contents being
This is a test.
The site loaded fine, and DNN continued to function as well. I added a sample web.config into the c:\websites\newapp\ folder from https://www.daniellittle.xyz/example-web-config-files-3-5-and-4-5/#Framework451 just to check that out, and the site continued to function as well.
I added dnn9.dnndev.me to my bindings on the DNNDEV.ME website as well, and it continues to function without problems.
Only real difference I can see from what I did, and you said you tested, is that I made an APPLICATION not a Virtual Directory in IIS for /NewApp/

Add Standalone ASP.Net Application Into Existing ASP.Net Website - not working

I have an asp.net '4.5' site (Orion Solarwinds) and I would like to add functionality. This can be done with a virtual directory, but adding anything to that folder will cause a recompile and interrupt service to the user.
It should be possible(and done it many times before) to 'just' add a application. So I should be able to use a separate application pool.
BUT what happens is that even with a index.html file in an empty application with a web.config in there, it still seems to inherit from the host webconfig. Thus this is not a Standalone ASP.Net Application in an existing website. I have tried to decouple this basic application - no joy. How can I fix this?
You can try using inheritInChildApplication by wrapping sections you don't want to inherit in host webconfig with this:
<location path="." inheritInChildApplications="false">
There's more details in this other thread

How to deny access to a file with ASP.NET web config but not just locally?

I have a problem with ASP.NET web configuration file. I want to deny some users or roles to accessing a specific PDF file. I am using ASP.NET membership and role management system. So I added this lines of codes to a Web.config file:
<location path="myfile.pdf">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
and put it to the directory witch the file is included in it. Now when I run the project in local system I can not access the PDF file wile I login with "admin" role. But when I publish the project on the web server I can not brows the folder but I can view the PDF file when I browse complete path to the PDF file. So:
I can not access: http://www.example.com/folder
but I can view: http://www.example.com/folder/myfile.pdf
IIS is probably serving the PDF file before ASP.Net gets its hands on it. Assuming you're using .Net 4.0, add this to your Web.config file to force all requests to flow through to ASP.Net:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<system.webServer>
You need to make IIS forward PDF requests to ASP.NET for your stuff to take place.
Example Article:
http://www.primaryobjects.com/CMS/Article112.aspx
Quoting relevant part from article:
Hooking PDF Files Into the Web
Application with IIS
It was easy testing the custom HTTP
handler in Visual Studio's built-in
web server, Cassini, since all
document types are automatically
processed in the web application by
default. However, IIS needs a few
tweaks. IIS will ignore sending
requests for static documents, such as
PDF files, to the ASP .NET web
application and will instead simply
serve the request. We need to
intercept the request and allow our
web application to process it first.
To do this, we'll need to setup an IIS
mapping for PDF files (*.pdf), telling
IIS to send the request to our web
application.
In IIS 5/6
Open the Internet Information Services (IIS) Manager.
For your web application, on the Directory tab, click the Configuration
button.
On the Mappings tab of the Application Configuration window,
click the Add button to add a new
Application Extension Mapping.
In the Executable field, enter: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
In the Extension field, enter: *.pdf
Select All Verbs and checkmark Script Engine and Check that file
exists.
In IIS 7
Open the Internet Information Services (IIS) Manager.
Open the Handler Mappings setting.
Add a Managed Handler.
For Request Path enter: *.pdf
For Type, select the custom HTTP handler for the application.
A shortcut to this in IIS 7, as
mentioned above in the article, is to
define the mapping in the web.config
within the system.webServer handlers
section, as follows:
<system.webServer>
...
<handlers>
<add name="PDF" path="*.pdf" verb="*" type="CustomFileHandlerDemo.Handlers.FileProtectionHandler" resourceType="Unspecified" />
...
</handlers>
</system.webServer>
The above code in the web
application's web.config will
automatically add the entry into the
IIS 7 Handler Mappings section.
The above steps may differ depending
on your version of IIS, but should be
similar for adding a document mapping
to the web application. Once
configured, requests for PDF documents
will be sent to the web application,
where you can process the request
before allowing access.
Remember, in Visual Studio's built-in
web server, module mappings are not
required, as all requests for files go
through the web application, making it
easy to test the custom http handler.
Because you don't use custom handler, you just need to set the handler to ASP.NET default handler. This is the same handler set to ".aspx" already in IIS.

Configure ASP.NET application to use two authentication methods?

I am new to ASP.NET development and moreover I am only extending an existing application which i did not create.
I have a working ASP.NET application which uses "Forms authentication" throughout all its pages. I have added a new webservice in a subfolder "webservices\Dummy.asmx". This webservice works fine but because it should be called by an external application which can't authenticate through a form, i need to enable "Integrated Windows Authentication (Basic Authentication or Digest Authentication)" ONLY for the subfolder "webservices".
I tried to configure it in IIS but it did not work.
So that i can set a different authentication method i have to create the folder "webservices" as an "Application". But if i do so then my function stops working with the error "Could not create type 'Dummy'."
Is it possible to have one web application and to authentication methods ?
If yes how is it configured in IIS ?
Or what would be the better way if i need ONLY one page (webservice) to use a different authentication then the rest of my application.
Thank you in advance for any information.
Bye
PS: I use Windows 2008 Server and the app runs on .NET Framwork 2.0
I tried to configure it in IIS but it
did not work. So that i can set a
different authentication method i have
to create the folder "webservices" as
an "Application". But if i do so then
my function stops working with the
error "Could not create type 'Dummy'."
This is the correct way. Can you explain the problem you are having here ? What is dummy ?
Mixing Forms and Windows Security in
ASP.NET
http://msdn.microsoft.com/en-us/library/ms972958.aspx
Web services that live in a larger application often do not need to be protected. If that's acceptable in your scenario, you can use a standard web.config construct to allow anonymous access to the service while still protecting the rest of the application.
Add a location node to the main configuration node that defines the rules for just the web service:
<location path="webservices\Dummy.asmx">
<system.web>
<authorization>
<!-- this overrides the parent app protection rules -->
<allow users="*" />
</authorization>
</system.web>
</location>

ASP.NET application in virtual folder uses web.config of application in root folder of website

I have several ASP.NET applications in virtual folders (already configured as applications, and with different application pools), but I want to install another ASP.NET application that will redirect to one of the virtual folders according to some criteria (from database and cookies).
All the applications in the virtual folders work fine, but if I install the root application, then I get some errors about duplicate web.config settings.
A workaround would be to create yet another virtual folder for the redirecting application, and use HTML redirection on the root site.
However, I would like to know if it is possible for a web application in a virtual folder to skip the website-root web.config in the .config hierarchy.
Thanks,
Luis Alonso Ramos
One option is to move all the settings of the web.config to a location path where you use the inheritInChildApplications attribute so that those settings are only applied for the parent application and not child applications, something like:
<location inheritInChildApplications="false">
... move all your settings here...
</location>

Resources