Do we need a Virtual Directory for WebService - c#

I have selected an Empty ASP.NET WebApp just to add a simple WebService 1.1 to in.
I can run my web service and see it working in the IE browser so my question is what is Virtual Directory for and do I even need it?

You don't need to have a virtual directory or a web application specific to your webservice. However, consider that your ASP.NET website or webservice is an application and requires an application pool to run in within IIS (or Cassini). Therefore, you need to make either the folder containing the webservice files or its parent a web application.
For example:
if your web service is hosted in such a disk folder:
C:\Inetpub\Wwwroot\Foo\Folder1\WebService\ASMX\MyGreatService.asmx
Any of these levels could be a web application:
C:\Inetpub\Wwwroot\Foo\Folder1\WebService\ASMX\
C:\Inetpub\Wwwroot\Foo\Folder1\WebService\
C:\Inetpub\Wwwroot\Foo\Folder1\
C:\Inetpub\Wwwroot\Foo\
(you get the picture...)
If you are doing this through IIS, when you create your website in IIS, it will automatically turn your top level directory into a web application. For example, if you create a website with its root folder at C:\Inetpub\Wwwroot\Foo\, that folder will already be a web application for you. To change any particular subfolder into its own web application, simply right-click on the folder you want to convert and select "Convert to Application".
For more details, I would refer you to the following articles:
IIS: Understanding Sites, Applications and Virtual Directories
IIS 7.0: Create and configure Virtual Directories
Web Application Vs. Virtual Directory

Related

Can you host a blazor app on IIS in a sub folder?

I have the basic blazor project that im trying to host in a specific way. I have managed to host the app in IIS where all the files were in the same folder. The issue im having is the web config in the root folder and then having the actual app itself in a subfolder.
IIS app file structure
im using blazor server which is sitting the "test" folder.
test folder where the blazor app is, seperate to the web config
Is this even possible to host in this way? or is there routing or config that needs to be done to get it to work?
Thanks,
So far I'm afraid it is unavailable to host application in site level. No matter I set the aspnet core handler in root level or folder level, change location value,change processPath. IIS just ignore the attribute even I have set it in both root level and folder level.
I think even you were able to host blazor in a sub-folder, Duplicate attribute verification is easy to crash the application when you need to publish something in root folder.
So the best way to handle this is convert test folder to an application. Then everything get isolated and start working.
interesting idea
I see no reason, why not to create a sub directory as website in iis. There have to be a extra app pool unmanaged for each.

Dynamics 365 WebAPI helper Configuration class doesn't find config file

I have a solution that outputs data from a WCF service and reads it from a Dynamics 365 WebAPI.
The main project is a WCF service that is hosted in IIS. While debugging I use IIS Express.
I have a data layer project (dll) that has the CRM WebAPI Helper Classes imported within the project.
When I launch the debugger (IISExpress), the data layer will use the WebAPI FileConfiguration helper class to try and read configuration from it. This step fails because it tries to find a config file with a name C:\Program Files (x86)\IIS Express\iisexpress.exe.config which doesn't exist. None of the project dlls exist in that directory.
I have created an IIS Virtual Directory and checked that the configuration points to the correct physical directory (where my solution is). I also tried incrementing the IISExpress port number by one so that it would create a new virtual directory.
My question is how to find the correct path for the data access dll regardless of the environment I'm in? The FileConfiguration helper class uses Directory.GetCurrentDirectory() and I'm not sure it it's always applicaple?
If I try to get the Assembly Path directly it will point to some temp directory that doesn't contain the config file.
I found out that I can get the path of the IIS application by using HttpRuntime.AppDomainAppPath.
How to get ASP.NET application path?

How to access folder in network which outside from project in MVC 4.0 ASP.NET?

One of my folder is reside in local network or local machine for upload and display attachments. I can not manage (upload or display) this in MVC 4.0, ASP.NET. For that I wrote path in appsetting of web.config. Please guide me how to manage it.
Simply having the path recorded and used does not mean that the application has the permissions to access it.
You need to ensure that the account that the web application runs under has the permissions to access this folder (the account details will be in the properties of the web server application pool that is setup for the site).
try to:
create a Site mapped on your attachments folder
In your project, add two AppSettings: AttachmentAbsoluteUrl, AttachmentFullname
When you have to download an attachment, you can use the Url defined in the AttachmentAbsoluteUrl AppSettings Key, when you have to upload/delete/add, use the AttachmentFullname key.
In this way you can manage both development and production environments, using different AppSettings values.
For example, in my local computer, I have the Attachments folder in the same directory of the project, in production server, I have a different folder outside the Site directory.
You have to check if the Identity of the Application Pool used by your Web application have the rights to modify the contents of the Attachments folder.
I hope this can help you

Bing Maps SharePoint Web Part with Service Refrence

I have a SilverLight application that uses a Linq-to-SQL service refrence. My service refrence is located at http://localhost:1832/PositionService.svc
When I start my project as a SharePoint Web Part this service is not a part of the SharePoint module. So it is not accessable because only the ".xap"-file is uploaded to SharePoint.
Can anyone give hints or help out in my problem?
When you upload the .xap, you should still be able to access the service but you have to make sure that the SharePoint user account has permission to access the service and you also have to add any necessary configurations settings, such as assemblies to be loaded and other, to Sharepoint-80 web.config file.

App_Code and server

I'm having a "tiny" issue with my App_Code folders.
I'm learning ASP.NET and, therefore, ordered a webserver with the support of ASP.NET 4.0. I'm using Visual Web Developer to program my webpages. When I upload my website to this webserver everything runs fine.
However, if I then add another web project to my server, my App_Code folder gets all messy. The server wants all my class files in the App_Code folder in the root. Is there any way I can create subdirectories in my App_Code folder or something to keep my projects organized or am I missing the point here?
You should take a look at codeSubDirectories in the web.config
Alright I found a solution to my problem. Although most of your answers might work aswell, this proved to be the best in my case. I created a subdomain and threw all files into that folder and it worked fine.
You should try to avoid using the App_Code folder for your own stuff, especially if you're using a web application project.
Whenever you convert a website to a web application project, the process actually renames your existing App_Code directory to Old_App_Code.
See Here, even though this is specific to converting .net 2.0 apps, I believe it still holds true in 4.0 since converting a 4.0 app does the same thing.:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly DO NOT want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
If you have access to a hosting control panel it's probably best to configure your hosting environment with a virtual folder for your second website and run it from the sub folder, e.g. www.example.com/project-b. The first site can still be running in the root folder, e.g. www.example.com.
So both sites will essentially be isolated from each other (just like they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).
If you don't have access to a configuration panel, most hosting providers are willing to add a virtual folder for you, since it's really not a special requirement.
The virtual folder should show up as a regular folder in your FTP folder, usually inside the www or wwwroot folder. Now you can copy your project files into that folder.
Take care to use root-relative paths for URLs in your second project, so all links will work even when the website is run from the subfolder. Root-relative URLs look like this:
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" />
<asp:Image runat="server" NavigateUrl="~/images/logo.png" />
This will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png when the website is deployed in the virtual folder.
If you need to re-use code from one site in the other, it's typically best to move such code into a separate Class Library project type, and then add a reference to that project to each website project (right-click the website project, choose Add reference..., then select the Projects tab and select the Class Library project).

Categories

Resources